You can use templates to accomplish something similar (but not exactly that):
template<class T>
void MyFunction()
{
T *tmp = new T();
}
and call it with MyFunction<MyClassName>()
.
Note that this way, you can’t use a “variable” in place of T
. It should be known at compile time.