Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8071045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:34:35+00:00 2026-06-05T13:34:35+00:00

So here is my dilemma: I have a base class (Let’s say a generic

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:34:38+00:00Added an answer on June 5, 2026 at 1:34 pm

    It sounds like you want Manager to have a vector of unique Persons, ie you can have a Worker, and a Person, and a ThirdPerson, but not more than one of each in the vector? Why not just overload a function in Person that returns a string label of the subclass and iterate through the vector calling pPerson->GetLabel() for each, and comparing it to the label of the new object you’re thinking of adding to the vector.

    Manager still only knows about the Person class, doesn’t have to know anything about the different subclasses of Person, but can get a unique string back from each type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my dilemma. We have a server with a path, say \server1\data$\foo\bar\stuff. I'm
I have a bit of a dilemma here. I have a drupal 7 database
Here's my dilemma: I have to RGBA RAW images: a master image (the first)
Here's my dilemma: I have two types of routes which are semantically very different,
Here is my dilemma: The Problem I have SubProgram (a DLL) that uses System.Data.SQLite
I have a dilemma going on here. I need to use a session to
Here's my dilemma. I have 2 animations that need to run sequentially. The first
Ok here's my dilemma. here's this code I have: If e.KeyCode = Keys.A Then
So I have public class Form1 : Form {} and class Updater {} And
Ok, here is my dilemma I have a database set up with about 5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.