Posts

Showing posts with the label pimpl-idiom

Pimpl - Why can make_unique be called on an incomplete type

Why does the make_unique call compile? Doesn't make_unqiue require its template argument to be a complete type ? struct F; int main() { std::make_unique<F>(); } struct F {}; The question orignated from my "problem" with my PIMPL implementation: I do understand why the destructor has to be user declared and defined inside the cpp file for the Implementation class (PIMPL). But moving the constructor of the class containing the pimpl- still compiles. class Object {}; class CachedObjectFactory { public: CachedObjectFactory(); ~CachedObjectFactory(); std::shared_ptr<Object> create(int id) const; private: struct CacheImpl; std::unique_ptr<CacheImpl> pImpl; }; Now the cpp file: // constructor with make_unique on incompete type ? CachedObjectFactory::CachedObjectFactory() : pImpl(std::make_unique<CacheImpl>()) {} struct CachedObjectFactory::CacheImpl { std::map<int, std::shared_ptr<Object>> idToObjects; }; //deferred destructor ...