auto_ptr compile error

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

  1. George2

    George2

    Joined:
    Feb 12, 2008
    Messages:
    108
    Hello everyone,


    Two questions,

    1.

    The following compiler error from the following code segment, is because delete statement from destructor of auto_ptr requires the declaration of destructor of wrapped object?

    Code:
    1>main.cpp
    1>d:\visual studio 2008\projects\test_autoptr2\test_autoptr2\main.cpp(10) : error C2512: 'Foo' : no appropriate default constructor available
    
    #include <memory>
    #include <iostream>
    
    using namespace std;
    
    class Foo;
    
    void func()
    {
    	auto_ptr<Foo> pf (new Foo());
    
    	cout << "I am here. " << endl;
    
    	return;
    }
    
    int main()
    {
    	func();
    
    	return 0;
    }
    
    class Foo {
    };
    
    2.

    If yes, how to define a destructor outside of the body of class declaration? I defined in this way, but compile can not pass.

    Code:
    Foo::~Foo()
    {
    
    }
    

    thanks in advance,
    George
    George2, Mar 21, 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,533
    Dave Rahardja
    Jan 11, 2005
  2. gg
    Replies:
    5
    Views:
    448
    msalters
    Aug 11, 2005
  3. George2

    compile error about auto_ptr

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

    auto_ptr assignment compile error

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

Share This Page