auto_ptr assignment compile error

Discussion in 'C Programming' started by George2, Mar 30, 2008.

  1. George2

    George2

    Joined:
    Feb 12, 2008
    Messages:
    108
    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
     
    George2, Mar 30, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Siemel Naran

    auto_ptr<Derived> to auto_ptr<Base>

    Siemel Naran, Jan 10, 2005, in forum: C++
    Replies:
    2
    Views:
    1,566
    Dave Rahardja
    Jan 11, 2005
  2. Chummaid@gmail.com

    Assignment Operator with auto_ptr

    Chummaid@gmail.com, May 12, 2005, in forum: C++
    Replies:
    3
    Views:
    478
    Stefan Strasser
    May 12, 2005
  3. George2

    compile error about auto_ptr

    George2, Feb 23, 2008, in forum: C Programming
    Replies:
    0
    Views:
    301
    George2
    Feb 23, 2008
  4. George2

    auto_ptr compile error

    George2, Mar 21, 2008, in forum: C Programming
    Replies:
    0
    Views:
    318
    George2
    Mar 21, 2008
  5. Sousuke
    Replies:
    9
    Views:
    1,163
    Bart van Ingen Schenau
    Mar 16, 2010
Loading...

Share This Page