template <class T>
T* create_class(T* object = nullptr)
{
if (obj == nullptr) {
obj = new T();
if (obj == nullptr)
throw Exception("Can't create " + std::string(name_of<T>()) + " object");
}
obj->init();
return obj;
}
...
MyClass* mc = create_class<MyClass>();
delete mc;