From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30580 invoked by alias); 13 Aug 2009 05:22:04 -0000 Received: (qmail 30552 invoked by uid 22791); 13 Aug 2009 05:22:02 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from kuber.nabble.com (HELO kuber.nabble.com) (216.139.236.158) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Aug 2009 05:21:57 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1MbSl8-0002Ni-Bp for gcc-help@gcc.gnu.org; Wed, 12 Aug 2009 22:21:54 -0700 Message-ID: <24949027.post@talk.nabble.com> Date: Thu, 13 Aug 2009 09:28:00 -0000 From: Mustafa4LP To: gcc-help@gcc.gnu.org Subject: Re: Copy constructor not called. In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit References: <24930356.post@talk.nabble.com> X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2009-08/txt/msg00113.txt.bz2 Hi Eljay, I know that design wise the copy constructor and assignment operator are not correct. Actually, I am not writing the code for application but trying some test case to understand C++ better. The original program that I posted was correct in terms of C++ standards, it came out to be a bug of GCC version 3.4.6. When I tried the same on GCC version 4.3 it executed as expected. Thanks for the help. Regards, Mustafa John (Eljay) Love-Jensen wrote: > > Hi Mustafa, > >> Please consider the following program: >> >> #include >> using namespace std; >> class A >> { >> public: >> A () >> { >> cout << "constructor" << endl; >> } >> A (A &a) >> { >> cout << "copy constructor" << endl; >> } >> A operator = (const A &a) >> { >> cout << "= operator" << endl; >> } >> }; >> int main() >> { >> A a; >> A b; >> b = ( b = a ); >> } > > Your "copy constructor" is not an appropriate copy constructor. > > Change it to: > > A(A const& a) > { > cout << "copy constructor" << endl; > } > > Also, your assignment operator is not an appropriate assignment operator. > > Change it to: > > A const& operator = (A const& a) > { > cout << "= operator" << endl; > return *this; > } > > HTH, > --Eljay > > > -- View this message in context: http://www.nabble.com/Copy-constructor-not-called.-tp24930356p24949027.html Sent from the gcc - Help mailing list archive at Nabble.com.