-
December 17th, 2003, 12:09 PM
#1
auto_ptr<ifstream> warning?
When I try to declare this in a header file I get a warning.
Code:
auto_ptr<ifstream> ifs;
The program works but how can I get rid of this warning?
C:\Program\Microsoft Visual Studio .NET 2003\Vc7\include\memory(484) : warning C4150: deletion of pointer to incomplete type 'std::basic_ifstream<_Elem,_Traits>'; no destructor called
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program\Microsoft Visual Studio .NET 2003\Vc7\include\memory(484) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program\Microsoft Visual Studio .NET 2003\Vc7\include\memory(483) : while compiling class-template member function 'std::auto_ptr<_Ty>::~auto_ptr(void)'
with
[
_Ty=std::ifstream
]
c:\MINT\mint1\XLoadAtoms.h(13) : see reference to class template instantiation 'std::auto_ptr<_Ty>' being compiled
with
[
_Ty=std::ifstream
]
-
December 17th, 2003, 12:18 PM
#2
-
December 17th, 2003, 12:24 PM
#3
Originally posted by Andreas Masur
[Moved thread]
I'm moved
I found out. I just forgot to include this header file,
Code:
#include < fstream>
Gosh do I hate to be a newbie.
-
December 17th, 2003, 12:28 PM
#4
The original code should be,
Code:
auto_ptr< ifstream> ifs;
I can't handle this quite yet.
-
December 18th, 2003, 10:37 AM
#5
What are you trying to do here ?
The purpose of auto_ptr is to delete memory which you have newed e.g.
Code:
{
auto_ptr<MyClass> pMyClass(new MyClass);
// to use
pMyClass->SomeFunction();
}
// gone out of scope, MyClass destroyed.
When the function containing the auto_ptr returns, then the newed memory will be released.
I don't understand why you're trying to use it with an ifstream.
Darwen.
-
December 18th, 2003, 10:41 AM
#6
Sorry, the site got rid of my angle brackets
Code:
auto_ptr[<]pMyClass(new MyClass)[>];
Darwen.
-
December 18th, 2003, 10:42 AM
#7
Nope, try again.
Code:
auto_ptr>CMyClass<(new CMyClass);
Darwen.
-
December 18th, 2003, 10:44 AM
#8
This is it !
Code:
auto_ptr<CMyClass>(new CMyClass);
At last.
Darwen.
-
December 18th, 2003, 10:45 AM
#9
Oh god, try again
Code:
auto_ptr<CMyClass> pMyClass(new CMyClass);
-
December 18th, 2003, 11:30 AM
#10
Originally posted by darwen
What are you trying to do here ?
The purpose of auto_ptr is to delete memory which you have newed e.g.
I'm declaring an auto_ptr< ifstream> variable in the header file of a class. At some point a new fstream is assigned to it. The purpose is to make sure the fstream gets destructed for sure. I've read in Effective C++ that the use of auto_ptr's is a way to ensure that. If I for example assign a new ifstream to this auto_ptr variable the old ifstream will get automatically deleted. To me it seams like a fool-proof way to avoid leaks?
-
December 18th, 2003, 04:29 PM
#11
Fair dues. You are right of course, you should be using auto_ptr to release any memory which is created.
Darwen.
-
December 18th, 2003, 10:42 PM
#12
Originally posted by darwen
Oh god, try again
Dude! Use the EDIT button...
Thought for the day/week/month/year:
Windows System Error 4006:
Replication with a nonconfigured partner is not allowed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|