From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 92664 invoked by alias); 29 May 2015 11:29:37 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 92650 invoked by uid 89); 29 May 2015 11:29:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mail.bfw-online.de Received: from mail.bfw-online.de (HELO mail.bfw-online.de) (62.245.186.164) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 29 May 2015 11:29:35 +0000 Received: from weller by mail.bfw-online.de with local (Exim 4.85) (envelope-from ) id 1YyITj-0001zQ-HN; Fri, 29 May 2015 13:29:31 +0200 Date: Fri, 29 May 2015 11:29:00 -0000 From: Weller To: gdb@sourceware.org Subject: Re: find_overload_match for constructor Message-ID: <20150529112931.GA1850@bfw-online.de> References: <20150508092906.GA23005@bfw-online.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="VbJkn9YxBvnuCH5J" Content-Disposition: inline In-Reply-To: <20150508092906.GA23005@bfw-online.de> User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-05/txt/msg00036.txt.bz2 --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1516 Still working on this problem. A full example would lool like the attachment. A being the base class and B being the constant class. Another option would be to do the calls manually. e.g. A a1 = A (INT) a1->i = 123 But it still presents the same issue. I need to find the correct constructor which takes the type argument so its not really an improvement. Anyone got any ideas how this could be achieved? Cheers, Lennart Weller On Fri, May 08, 2015 at 11:29:06AM +0200, Weller wrote: > Hey everyone, > > I'm currently stomped on how to call_function_by_hand for a constructor. > Basically I have a class in C++ which wraps multiple native data types to > the underlying base class like this: > > class constant_t: public value_t > { constant_t (int); > constant_t (double); > constant_t (const char *); > } > > Now when I have a command line like > (gdb) p $testnr1 + 0.1 > I need the function call to the constructor of constant_t so that I can > use the operator+ on the value_t of $testnr1. > > I looked through the code and the only thing I could find which came > close to this was the code used for the operator overload on C++ classes > with find_overload_match but I can't quite figure out how I would call > this in case of an overloaded constructor. Do I need to create an object > of type constant_t with it being passed to **args and **objp? In that > case how would I achieve that, as the the created object is kinda what I > want in the first place. > > Any help is appreciated, > Lennart --VbJkn9YxBvnuCH5J Content-Type: text/x-c++src; charset=us-ascii Content-Disposition: attachment; filename="simple.cpp" Content-length: 490 #include enum T { INT, DOUBLE, STRING }; class A { public: T t; int i; double d; char *s; A (enum T); }; class B : public A { public: B (int); B (double); B (const char *); }; A::A (enum T t) { this->t = t; } B::B (int i) : A (INT) { this->i = i; } B::B (double d) : A (DOUBLE) { this->d = d; } B::B (const char *s) : A (STRING) { this->s = strdup (s); } int main () { A a1 = B (123); A a2 = B (1.23); A a3 = B ("foo"); return 0; } --VbJkn9YxBvnuCH5J--