Re: auto_ptr compile error
- From: David Wilkinson <no-reply@xxxxxxxxxxxx>
- Date: Thu, 20 Mar 2008 23:22:05 -0400
George wrote:
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 {
};
[/Code]
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()
{
}
[/Code]
George:
The error message says nothing about destructors.
If you move the definition of class Foo to above func() then it will compile. The default constructor and destructor of Foo will be used.
--
David Wilkinson
Visual C++ MVP
.
- Follow-Ups:
- Re: auto_ptr compile error
- From: George
- Re: auto_ptr compile error
- References:
- auto_ptr compile error
- From: George
- auto_ptr compile error
- Prev by Date: Re: QueryPerformanceFrequency
- Next by Date: Re: auto_ptr compile error
- Previous by thread: Re: auto_ptr compile error
- Next by thread: Re: auto_ptr compile error
- Index(es):
Relevant Pages
|