Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > auto_ptr assignment compile error

Reply
Thread Tools

auto_ptr assignment compile error

 
 
George2 George2 is offline
Senior Member
Join Date: Feb 2008
Posts: 108
 
      03-30-2008
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(1 : 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>: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>: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>: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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
explicit auto_ptr<T>::auto_ptr(T*) ? Sousuke C++ 9 03-16-2010 11:54 AM
auto_ptr compile error George2 C++ 0 03-21-2008 03:00 AM
compile error about auto_ptr George2 C++ 0 02-23-2008 02:10 PM
Assignment Operator with auto_ptr Chummaid@gmail.com C++ 3 05-12-2005 09:05 PM
auto_ptr<Derived> to auto_ptr<Base> Siemel Naran C++ 2 01-11-2005 04:45 AM



Advertisments