As user3755692 already mentioned, you can't create classes on runtime. But if you really desperate about idea of dynamically creation of some objects with different fields and methods, you can try a component-based design. It's really effective, but sometimes hard to implement, approach.
It's like you have a dummy object, which is just a container of components, like so:
class BaseObject
{
public:
void addComponent(IComponent* component);
Icomponent* getComponent();
void executeComponent(int id);
void updateAllComponents();
private:
vector<IComponent*> _components;
};
And you have various components inherited from IComponent
interface(which provides some basic functionality and pure virtual methods), which you can add to your base object.
Components can be anything:
// Component that stores int value
class IntComponent : public IComponent
{
public:
// This is something inherited from IComponent
virtual void init()
{
integerValue = 0;
}
public:
int integerValue;
};
// Component that allows you to print something in console
class PrintingComponent : public IComponent
{
public:
// This is something inherited from IComponent
virtual void init()
{
}
public:
void print(const char* phrase)
{
cout<<phrase<<endl;
}
};
You can combine different components in your base object to achieve deserved functionality. And you can create such objects using a some kind of configuration file. Like simple *.txt file:
[OBJECT]
COMPONENT_INT,
COMPONENT_PRINT
[OBJECT]
COMPONENT_INT,
COMPONENT_FILEREADER
Then you will parse it and create two objects with different sets of components, which then can be used inside of your program.
Here's some useful articles about this approach:
1)http://www.randygaul.net/2013/05/20/component-based-engine-design/
2)http://gameprogrammingpatterns.com/component.html
3)Component based game engine design - much useful links here too
Those articles above focused on gamedev mainly, but there's a very good explanations.
Good luck!