Re: Copy constructor not called.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <iostream>
>> 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.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux