Copy constructor with non const rhs arg

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

 



This code does not compile on gcc (3.2.2 on rh9 - 3.3 on suse 9)
 
class test
{
public:
int x;
test(test &rhs)
{
	x = rhx.x;
}
};

test foo();
int main(int argc, char* argv[])
{
	test dd = foo();
	return 0;
}

The test dd line gets hit saying there is no match for test::test(test), the
candidates are test::test(test&)
If I change the copy constructor to 'test(const test&)' it compiles fine.

What am I trying to do? In real life the class contains an auto_ptr - since
the auto_ptr copy constructor updates the rhs you cannot pass it in with
const. (Note the auto_ptr copy constructor itself is declared with a non
const rhs - and code using it compiles fine - this is really puzzling)

Also if I change foo to 'test &foo()' it compiles fine (but of course this
is totally different semantics)
Note also that MSFT vs 2003 compiles this code quite happily.



[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