I have some code in a header that looks like this:
#include <memory>
class Thing;
class MyClass
{
std::unique_ptr< Thing > my_thing;
};
If I include this header in a cpp that does not include the Thing
type definition, then this does not compile under VS2010-SP1:
1>C:\Program Files (x86)\Microsoft
Visual Studio
10.0\VC\include\memory(2067): error C2027: use of undefined type ‘Thing’
Replace std::unique_ptr
by std::shared_ptr
and it compiles.
So, I’m guessing that it’s the current VS2010 std::unique_ptr
‘s implementation that requires the full definition and it’s totally implementation-dependant.
Or is it? Is there something in it’s standard requirements that makes impossible for std::unique_ptr
‘s implementation to work with a forward declaration only? It feels strange as it should only hold a pointer to Thing
, shouldn’t it?