I'm having trouble using std::auto_ptr
. I try to compile the following on Ubuntu 11.10 using GCC 4.6.1, and I get the error message error: no match for call to ‘(std::auto_ptr<int>) (int*)’
.
#include <memory>
#include <iostream>
class Toy {
public:
std::auto_ptr<int> foo;
Toy() {
foo(new int(3));
}
};
int main() {
Toy toy;
std::cout << *toy.foo << std::endl;
return 0;
}
I was pretty sure a std::auto_ptr< T >
takes in a T*
as its constructor arguments, but apparently not... My apologies if this is a trivial or duplicate question, but I searched the archives, and haven't found an answer. Places like this seem to suggest that the above code should work. Anyway, any help would be appreciated!