This question already has an answer here:
When defining the following class
class Foo
{
public:
Foo (void);
~Foo (void) = default;
protected:
class FooImpl;
std::unique_ptr <FooImpl> _impl;
//...
};
Foo::Foo (void) : _impl (std::make_unique <Foo> ()) {
}
I get the following error (icpc):
/home/toolworks/gcc/4.8.2/bin/../include/c++/4.8.2/bits/unique_ptr.h(65): error: incomplete type is not allowed static_assert(sizeof(_Tp)>0, ^ detected during:
instantiation of "void std::default_delete<_Tp>::operator()(_Tp *) const [with _Tp=FooImpl]" at line 184 instantiation of "std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp=FooImpl, _Dp=std::default_delete]" at line 290 of "/home/toolworks/gcc/4.8.2/bin/../include/c++/4.8.2/bits/shared_ptr_base.h" instantiation of "void std::_Sp_counted_ptr<_Ptr, _Lp>::_M_dispose() [with _Ptr=Foo *, _Lp=__gnu_cxx::_S_atomic]" at line 286 of "/home/toolworks/gcc/4.8.2/bin/../include/c++/4.8.2/bits/shared_ptr_base.h" implicit generation of "std::_Sp_counted_ptr<_Ptr, _Lp>::~_Sp_counted_ptr() [with _Ptr=Foo *, _Lp=__gnu_cxx::_S_atomic]" at line 286 of "/home/toolworks/gcc/4.8.2/bin/../include/c++/4.8.2/bits/shared_ptr_base.h" instantiation of class "std::_Sp_counted_ptr<_Ptr, _Lp> [with _Ptr=Foo *, _Lp=__gnu_cxx::_S_atomic]" at line 286 of "/home/toolworks/gcc/4.8.2/bin/../include/c++/4.8.2/bits/shared_ptr_base.h" instantiation of "std::_Sp_counted_ptr<_Ptr, _Lp>::_Sp_counted_ptr(_Ptr) [with _Ptr=Foo *, _Lp=__gnu_cxx::_S_atomic]" at line 452 of "/home/toolworks/gcc/4.8.2/bin/../include/c++/4.8.2/bits/shared_ptr_base.h" instantiation of "std::__shared_count<_Lp>::__shared_count(_Ptr) [with _Lp=__gnu_cxx::_S_atomic, _Ptr=Foo *]" at line 740 of "/home/toolworks/gcc/4.8.2/bin/../include/c++/4.8.2/bits/shared_ptr_base.h" instantiation of "std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Tp1 *) [with _Tp=Foo, _Lp=__gnu_cxx::_S_atomic, _Tp1=Foo]" at line 113 of "/home/toolworks/gcc/4.8.2/bin/../include/c++/4.8.2/bits/shared_ptr.h" instantiation of "std::shared_ptr<_Tp>::shared_ptr(_Tp1 *) [with _Tp=Foo, _Tp1=Foo]" at line ... of "main.cc"
However, When I define a non-default destructor it compiles:
Foo.h
class Foo
{
public:
Foo (void);
~Foo (void);
protected:
class FooImpl;
std::unique_ptr <FooImpl> _impl;
//...
};
Foo.cc
Foo::~Foo (void) {
}
it compiles. I saw at some places that said that the "=default" should compile, and it is not the same class as implicit default function (I'm new to c++11).
So, why doesn't the first Foo compiles?
Note: I' don't see how it is duplicated since I've asked about defaulted destructor, not a default destructor
Aucun commentaire:
Enregistrer un commentaire