Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a new object from dynamic type info

Tags:

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 simple 3 class hierarchy:

class Base
class Foo : public Base
class Bar : public Base

Now suppose I give you an object cast as type Base -- which is in reality of type Foo. Is there a way to query the type and use that info to later create new objects of type Foo?