auto_ptr assignment compile error

Joined
Feb 12, 2008
Messages
108
Reaction score
0
Hello everyone,


I posted the code and related compile error below. My analysis below,

1. I think the reason of compile error is, the copy constructor of Goo accepts const reference as input parameter, so the pf member of input parameter is also treated const?
2. And since auto_ptr does not have a copy constructor which accepts const reference auto_ptr as input parameter, the compile error occurs.

My analysis (1) and (2) are both correct?

What makes me confused is it seems the compile error message does not reflect my analysis (1) and (2) above. Any ideas?

Code:
#include <memory>

using namespace std;

// Foo is Pimpl class for Goo, suppose.
class Foo {

};

class Goo {

public:

	auto_ptr<Foo> pf;

	Goo (const Goo& input)
	{
		this -> pf = input.pf;
	}
};


1>d:\visual studio 2008\projects\test0330\test0330\main.cpp(18) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const std::auto_ptr<_Ty>' (or there is no acceptable conversion)
1> with
1> [
1> _Ty=Foo
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\memory(689): could be 'std::auto_ptr<_Ty> &std::auto_ptr<_Ty>::eek:perator =<Foo>(std::auto_ptr<_Ty> &) throw()'
1> with
1> [
1> _Ty=Foo
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\memory(701): or 'std::auto_ptr<_Ty> &std::auto_ptr<_Ty>::eek:perator =(std::auto_ptr<_Ty> &) throw()'
1> with
1> [
1> _Ty=Foo
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\memory(707): or 'std::auto_ptr<_Ty> &std::auto_ptr<_Ty>::eek:perator =(std::auto_ptr_ref<_Ty>) throw()'
1> with
1> [
1> _Ty=Foo
1> ]
1> while trying to match the argument list '(std::auto_ptr<_Ty>, const std::auto_ptr<_Ty>)'
1> with
1> [
1> _Ty=Foo
1> ]


thanks in advance,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top