auto-ptr

Why doesn't auto_ptr<T> have operator!() defined?

The Title pretty much sums up my question. Why can't the following be done to check for a null pointer? auto_ptr<char> p( some_expression ); // ... if ( !p ) // error This must be done instead: if ( !p.get() ) // OK Why doesn't auto_ptr<T> simply have operator!() defined? ...

auto_ptr and containers - C++

Hi. I'm currently working on a 2D game engine and I've read about auto_ptr's and how you should never put them in standard containers. My engine has this structure: StateManager -- has many --> State's. States are created and allocated in main, outside of the engine. I want the engine to store a list/vector of all the states so I can...

question about auto_ptr::reset

please can anybody explain this code from C++ Reference site: #include <iostream> #include <memory> using namespace std; int main () { auto_ptr<int> p; p.reset (new int); *p=5; cout << *p << endl; p.reset (new int); *p=10; cout << *p << endl; return 0; } ...

Why does `myvector.push_back(autoPtr.release())` provide the strong exception safety guarantee?

EDIT: I should've mentioned, I was looking at the documentation for Boost's ptr_sequence_adapter and it claims that their adapter for template< class U > void push_back( ::std::auto_ptr<U> x ); is equivalent to doing vec.push_back(autoPtr.release()); and also provides the strong exception guarantee. And then I realized I was confusing t...

Code Review question - should I allow this passing of an auto_ptr as parameter?

Consider the following example code which I have recently seen in our code base: void ClassA::ExportAnimation(auto_ptr<CAnimation> animation) { ... does something } // calling method: void classB::someMethod() { auto_ptr<CAnimation> animation (new CAnimation(1,2)); ClassA classAInstance; classAInstance.ExportAnimation(animation) ...

std::auto_ptr to std::unique_ptr

With the new standard coming (and parts already available in some compilers). The new type std::unique_ptr is supposed to be a replacement for std::auto_ptr. Does their usage exactly overlap (so I can do a global find/replace on my code (not that I would do this, but if I did)) or should I be aware of some differences that are not ap...

auto_ptr Traps and Pitfalls

Besides all the known benefits of using auto_ptrs, what are auto_ptr "worst-practices"? Creating STL contrainers of auto_ptrs. auto_ptrs don't fulfill the 'CopyConstructable' requirement. See also Scott Meyer's "Effective STL", item 8. Creating auto_ptrs of arrays Upon destruction, auto_ptr's destructor uses 'delete' (and never 'delet...

Difference between pointer and smart pointer

Can you tell me what is wrong with this piece of code? I got asked this in an interview and I am not sure what's wrong with it tClass is a test class with a method printSomething that prints members of tClass. tClass * A = new tClass(); f(A); A->printSomething(); auto_ptr<tClass> * B = new tClass(); f(B); B-> printSomething(); or ...

auto_ptr with swig

Hi, I'm trying to wrap a C++ library which uses auto_ptr. I'm using swig and want to generate python bindings. I'v seen the section of the swig docu on how to use swig with smart pointers here[0]. But I can't get it to work. swig generates code that wants to initialize the auto_ptr using a const reference, but auto_ptr defines the cop...

C++ std::auto_ptr copy constructor

std::auto_ptr lacks const copy constructor, therefore I cannot use it directly in collections. is there some way to have for example vector of std::auto_ptr without using boost pointer collection template? ...