public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Copy constructor not called.
@ 2009-08-12 10:03 Mustafa4LP
  2009-08-12 11:28 ` Sven Eschenberg
  2009-08-12 20:04 ` John (Eljay) Love-Jensen
  0 siblings, 2 replies; 4+ messages in thread
From: Mustafa4LP @ 2009-08-12 10:03 UTC (permalink / raw)
  To: gcc-help


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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-08-13  5:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-12 10:03 Copy constructor not called Mustafa4LP
2009-08-12 11:28 ` Sven Eschenberg
2009-08-12 20:04 ` John (Eljay) Love-Jensen
2009-08-13  9:28   ` Mustafa4LP

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).