I want all objects derived from Initable to call terminate() on destruction. To do this, I create shared_ptr with user deletion.
My problem is that I cannot access the protected ctor of derived classes to create an instance in the Initable factory method.
Ctor must be protected to prevent instantiation without using the factory method.
class Initable { public: virtual void terminate() = 0; template<typename T, typename... Ts> static shared_ptr<T> make_initable(const Ts &... args) { return shared_ptr<T>(new T(std::forward<const Ts>(args)...), [] (Initable * aptr) { cout << "custom deleter" << endl; }); } }; class B : public Initable { friend class Initable;
I would like to avoid declaring as a friend of each derived class, what can I do?
source share