non-const copy ctor

Christian Fröbel
Sat Apr 8 00:35:00 GMT 2006

Hi there,

I'm having problems with a non-const copy constructor. The following code 
doesn't compile:

class A
	A () {}
	A (A&) {} // non-const copy ctor

A create()
	return A(); // <=== problem

The compilation stops with the following message:
In function ‘A create()’:
error: no matching function for call to ‘A::A(A)’
note: candidates are: A::A(A&)

If I provide a const copy constructor  (A (const A&)) everything works fine; 
but this is not what I want.

I think this is similar to what std::auto_ptr does. It also has a non-const 
copy constructor. But I also noticed some strange auto_ptr_ref-stuff there 
which I never understood. Maybe that's working around this problem.

btw: I was doing exactly that on a windows machine with Visual Studio 
7.something without any problems.

Someone having a clue?

My version of g++ is
g++ (GCC) 4.0.2 20050901 (prerelease) (SUSE Linux)


More information about the Gcc-help mailing list