[Solved] Is it possible to force c++ class instantiation on the heap?
Just make ctor private/protected and provide a static method(s) to create an instance: class HeapOnly { HeapOnly(); HeapOnly( int i ); public: static HeapOnly *create() { return new HeapOnly; } static HeapOnly *create( int i ) { return new HeapOnly( i ); } }; You may consider to return a std::unique_ptr in general case, but … Read more