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 8997011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:49:51+00:00 2026-06-15T23:49:51+00:00

I have 5 classes that called operators : * Enter(x) * Exit(x) * Push(b,x,y)

  • 0

I have 5 classes that called operators :

 * Enter(x)
 * Exit(x)
 * Push(b,x,y)
 * TurnOn(x)
 * TurnOff(x)

And 3 more classes that are called Predicates :

 * At(x,y) - example : At(Robot,Room3) , At(Box1,Room1) , At(Box3,Corridor)
 * SwithOn(x) - SwitchOn(Room2)
 * SwitchOff(x) - SwitchOff(Room1) , SwitchOff(Room4)

And I want to have good data structure the store them .

At first, I created two base classes and used inheritance:

  • Class Predicate for At(x,y) , SwithOn(x) and SwitchOff(x)

  • Class Operator for Enter(x) , Exit(x) , Push(b,x,y) , TurnOn(x) , TurnOff(x) .

And I added two deques :

std::deque<Operator> operators;
std::deque<Predicate> predicates;

And then ,when I create for instance a Exit operator :

Exit myExit ;

and push it into the the deque :

operators.push_back(myExit); // this works fine 

But I when I’d try to extract some kind of element from operators deuqe , I’d have to use some kind of casting .

  1. Is it possible to have a data structure that can store multiple (different types) objects ?

  2. I’m still at the stage of the planning , can you suggest maybe some other kind of design so I won’t have problems with extracting elements ? the best thing I can think of is polymorphism …

Regards

  • 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-15T23:49:52+00:00Added an answer on June 15, 2026 at 11:49 pm

    For your specific requirements I would look at making the Operator polymorphic and store the data in a boost pointer containers like ptr_vector. After all, it makes sense that the various specific operations all have in common that they are operators.

    Your current implementation with the basic std::deque<> will lead to object slicing as you’re only storing the base class, so that’s not going to work. In this particular case where polymorphism is desired, you really need to be able to store a pointer to the object instead. In your case, you probably want to use a

    boost::ptr_vector<Operator> something;
    

    If you can’t use boost, the other option is to use a standard container with something like a std::shared_ptr, for example like this:

    std::deque<std::shared_ptr<Operator> > something;
    

    You don’t want to store raw pointers in a std::vector as that leads to all sorts of interesting lifetime management issues that are easily avoided.

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

Sidebar

Related Questions

I have three classes that all have a static function called 'create'. I would
If I have a class called A and I have two classes that derive
I have a bas class called Media with two classes that inherit from it,
I have classes that are named exactly the same across different plug-ins that I
I have classes that are needed in both my web service and my server.
I have three classes that I am using and have shortened for ease of
I have some classes that are used for Styling and all of them display
I have 2 classes that have exact two functions. The difference between them is
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have two classes that refer to each other, but obviously the compiler complains.

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.