non-const copy ctor

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

 



Hi there,

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

class A
{
public:
	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)

Thanks,
  Christian


[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