Is it possible to avoid having full class definition visible when using it in standard container of smart pointers? For example I can't get the following to compile:
#include <memory>
#include <map>
class Foo;
class Bar {
public:
Bar();
std::map<int, std::unique_ptr<Foo>> myMap;
};
The Clang compiler seems to insist on having full definition of Foo
available when compiling Bar
. Is there a technique I could use to avoid having to include Foo.h?
Edit1:
error: invalid application of 'sizeof' to an incomplete type 'Foo': static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Edit2: No it is not a duplicate of is std::unique_ptr required to know the full definition. Just using unique_ptr does not necessarily requires full definition, but using it inside of standard container introduces additional wrinkles.
Edit3: It turns out I can achieve (almost) what I want by introducing a base class with a virtual destructor. Then a class that has a container of smart pointers to base class will compile w/o a problem. Nothing else has to be present in base class and base class must be fully visible. This way all complexities of derived classes may be hidden when container is compiled.