Copy constructor not called.

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

 



Hi all,

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 );
}


Following error is issued while running the above test case on gcc 3.4.6

test007.cpp: In function `int main()':
test007.cpp:23: error: no matching function for call to `A::A(A)'
test007.cpp:11: note: candidates are: A::A(A&)

However, if I change the argument of copy constructor to "const A &", the
program compiles finely.
I could not understand why const is required in copy constructor for running
the test case.

Also note that in the output of the modified program (which compiled
finely), no copy constructor is called.
I am running the test case with --no-elide-constructors option to disable
the RVO (so that I can get all copy constructor calls).

Thanks in advance for any help.

Regards,
Mustafa 
-- 
View this message in context: http://www.nabble.com/Copy-constructor-not-called.-tp24930356p24930356.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