Basically what I want is:
class MyClass{
public:
MyClass() = default;
// what should I do?
}
MyClass mc; // compile time error;
auto pmc = new MyClass; //OK
delete pmc; //OK too
I know I can make it heap-only by hiding constructor (can not new outside of the class now) or hiding destructor (can not delete outside of the class now) or hiding both. What if I don't want to introduce some new named function and just want the good old new and delete? Is it possible (even with hack)?
MyClass
and give a more motivated examplenew
operator were overloadable in such a way that it could return instances of the class, and could accept any number of arguments, just like constructors, so that we could write things like :auto px = new X(arg0, arg2, arg3);
.... anddelete
be just like the destructor.