I am currently working on a 2D game project and I want to switch from Delphi to C++.
In Delphi, I could declare an array which had the type of a class Entity
, and I could put Entity
s as well as objects of classes which are derived from Entity
into it.
This would be very important for me, as it seems logical that all entities should be stored and managed in one place.
- Is this possible in C++?
(Why not if it is in Delphi?)
What other choices to achieve something similar do I have?
I would need to do something like below:
#include <vector>
using namespace std;
class Entity
{
public:
int id;
};
class Camera : Entity
{
public:
int speed;
};
int main()
{
Entity point;
Camera camera;
vector<Entity> vec;
vec.push_back( point );
vec.push_back( camera ); //Why can't I do that?
}
I hope I have made myself clear enough and I'd really appreciate your help