In C++, is there any way to query the type of an object and then use that information to dynamically create a new object of the same type?
For example, say I have a
class Base { public: virtual ~Base() { } }; class Foo : public Base { }; class Bar : public Base { }; template T1* fun(T1* obj) { T2* temp = new T2(); return temp; } int main() { Base* b = new Foo(); fun(b); }