Given that I have a forward declared type:
class Foo;
I want to make a unique_ptr
to this type:
unique_ptr<Foo> pFoo;
This works fine in visual-studio-2017 but I can't make it work in visual-studio-2012.
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(1150): error C2027: use of undefined type
Foo
(....\src\STETestbed\STETestbed.cpp)
O:\Engine\stetestbed\include\STETestbed\ComponentDirector.h(26) : see declaration ofFoo
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(1149) : while compiling class template member functionvoid std::default_delete<_Ty>::operator ()(_Ty *) throw() const
with
[
_Ty=Foo
]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(1444) : see reference to function template instantiationvoid std::default_delete<_Ty>::operator ()(_Ty *) throw() const
being compiled
with
[
_Ty=Foo
]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\type_traits(743) : see reference to class template instantiationstd::default_delete<_Ty>
being compiled
with
[
_Ty=Foo
]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(1281) : see reference to class template instantiationstd::is_empty<_Ty>
being compiled
with
[
_Ty=std::default_delete
]
O:\Engine\stetestbed\include\STETestbed\ComponentDirector.h(63) : see reference to class template instantiationstd::unique_ptr<_Ty>
being compiled
with
[
_Ty=Foo
]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(1151): error C2338: can't delete an incomplete type (....\src\STETestbed\STETestbed.cpp)
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(1152): warning C4150: deletion of pointer to incomplete typeFoo
; no destructor called (....\src\STETestbed\STETestbed.cpp)
O:\Engine\stetestbed\include\STETestbed\ComponentDirector.h(26) : see declaration ofFoo
Was there a workaround for that back in the dark ages, or can I just not forward declare?
pFoo
a member or a variable? Also, if visual studio 2012s standard library is not C++11 compliant, could you useboost::scoped_ptr
instead? – ArtyerpFoo
is a member. I haven't included Boost in this project, and I think I'd surrender my forward declaration long before I did. VS2012 does supportunique_ptr
but yeah, it seems like it is not fully supported. – Jonathan MeepFoo
implemented in the header or in the.cpp
? (Defaulted/not user-declared counts as "in the header".) If the former is the case, try the latter. – Max Langhof