So here is my dilemma:
I have a base class (Let's say a generic Person class):
class Person{
public:
Person();
~Person();
virtual void Init();
virtual void SaySomething();
};
Now I want to have other classes inherit these methods.
class Worker: public Person{
public:
Worker();
~Worker();
void Init(){
// would do some special initializing.
}
void SaySomething(){
// Print something about the worker.
}
};
Now I would have a manager class:
class Manager{
public:
void Init();
void Run();
void SwitchPerson(Person* p);
protected:
vector<Person*> people;
};
The example I have given with the Worker being the child class of a Person is probably not the best. But the point is not the content of the class, it's the inheritance, and more specifically how classes understand and know of other classes.
Now in my main function I would have the following:
int main()
{
Manager* m = new Manager();
m->Init();
// Create a new worker;
Person* w = new Worker();
m->SwitchPerson(w);
return 0;
}
Now I am not sure if this is the right way of approaching the problem. The problem is that there can be unlimited amount of child classes and the manager class can't know about them. The manager class only knows about the parent (Person) class. So the SwitchPerson would add the new Worker class of type Person(Now i'm not sure if this is structurally incorrect, I have a feeling it is.) to the vector. But first it needs to make sure that there are no Worker Classes already in the vector. I tried using typeid.name but this obviously returns the name of the parent(Person) class.
I thought of using a template with a vector.. but again that would require the manager class to know about the Worker or any other children classes.
If you need me to explain anything else or add any relevant information just let me know.
EDIT:
Note: The terms Person, Worker, and Manager is irrelevant. It could be Camera, Lens, and Stage for all that matters.
SwitchPerson:
Let's say only one person could be active at once. It would make even more sense with the Camera, Lens, and Stage analogy. As only one camera can go to the screen lets say.
Let's say we are keeping with the Camera analogy. We have our first scene and we first call SwitchCamera() and pass in the new Camera. But the problem is the Stage object (Which would be the manager) does not know about the lens or the different types of lenses. There could be 100 or 10000. It doesn't matter. The Scene only knows about the camera which is a base class to all of the lens classes.
So when we switchCamera() we can then utilize the object to control the lens let's say (not very realistic but whatever). All of the controls are implemented first as virtual members inside the Camera base class. So the lenses classes all have the same members.
Now you have finished with the first scene and want to switch camera again. You would once again call SwitchCamera() and pass in the new second camera. In the switch camera the goal would be to set the passed camera object as it's active camera, then push it to the vector.
But we dont want two copies of the same lenses. This is where the problem lies. I want to be able to check whether the passed in Camera* camera = new Lense123(); is already inside the vector. If it is then I want to use the original one and discard the newly passed one.