I have some code that uses std::auto_ptr
and gives ugly warnings about deprecated std::auto_ptr
(GCC 4.7.1 on Suse Linux 12.2) when compiling.
So I have tried the following (since I found some source that states std::unique_ptr
should be the appropriate equivalent)
template<typename T>
struct AutoPtr
{
#ifdef COMPILE_FOR_CX11
typedef std::unique_ptr<T> Type;
#else
typedef std::auto_ptr<T> Type;
#endif
};
and replaced any references to std::auto_ptr<T>
with AutoPtr<T>::Type
, but got compile errors when using this option.
I'm pretty sure I want to use something like std::auto_ptr
at these pieces of code and I'm aware about the culprits and deficiencies of it. The errors I get seem to correlate about construction issues when std::unique_ptr
is used.
As a side note: The final class used for construction is an inheriting type of T
, the code looks like:
class MockClass;
class Client
{
public:
Client();
Client(const Client& rhs);
private:
mutable AutoPtr<MockClass>::Type embeddedMock;
};
Client::Client()
: embeddedMock(new ::testing::NiceMock<MockClass>())
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Getting errors here!
{
}
Client::Client(const Client& rhs)
: embeddedMock(rhs.embeddedMock)
{
}
So what's a full compliant smart pointer from the c++11 set, I can use here?