|
-
June 28th, 2012, 02:30 AM
#1
auto_ptr
Hi,
I have a few questions regarding this auto_ptr
1) I should only use auto_ptr within a function??
2) Can i use auto_ptr<int> or auto_ptr<SomeClass> in a class?
example:
Code:
class Test
{
private:
auto_ptr<int> ptrData;
}
If not why?
3)auto_ptr<std::vector> vec1 for example, why is it after copying such as
auto_ptr<std::vecotr> vec2(vec1), vec2 becomes unmodifiable? how to get around this?
-
June 28th, 2012, 03:10 AM
#2
Re: auto_ptr
 Originally Posted by mce
3)auto_ptr<std::vector> vec1 for example, why is it after copying such as
auto_ptr<std::vecotr> vec2(vec1), vec2 becomes unmodifiable? how to get around this?
You probably mean to say that vec1 no longer owns the vector. Basically, auto_ptr has unusual copy semantics...
 Originally Posted by mce
2) Can i use auto_ptr<int> or auto_ptr<SomeClass> in a class?
... so if you have an auto_ptr member in a class, and you don't disable copying, you'll have to worry about the unusual copy semantics that objects of your class will have...
 Originally Posted by mce
1) I should only use auto_ptr within a function??
... hence using an auto_ptr in the way you would use Boost's scoped_ptr is a way to keep things simple.
Note that the 2011 version of the C++ standard introduces std::unique_ptr and deprecates std::auto_ptr (because of the problems that it can cause, and the fact that unique_ptr can replace it for what it is useful for).
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
|