• Advertisement
Sign in to follow this  

Unspecified objects as function parameters

This topic is 4368 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya I am trying to create an "Action Queue" for a game I am working on. This will consist of an std::Queue with classes called "Action" (surprise!). Each Action will have a pointer to the function that needs to be called when it is used and a list of parameters. As the functions have different parameters I have to ask: 1. Is there any way of keeping a list of unspecified objects (I have only used std::vector before and that would be useless for this)? 2. Is it allowed to put an unspecified object as a function parameter, if not can you please give me an example of the syntax used for the conversion?

Share this post


Link to post
Share on other sites
Advertisement
I think what you need could be accomplished with inheritence. Define a base class and derive all classes that you want to be able to pass from that. Then, in the function that you want to take the classes you would specify the base class as the argument. Then, all derived classes can be passed through that function.

Share this post


Link to post
Share on other sites
How will the function handling the Action objects 'know' what parameters to pass? It seems easier to either pass the same thing to every Action object or to pass the arguments at the time the Action is created, not when it is executed. You could also combine the two.

[edit] tstrimp's idea seems like a good way to get around the problem. The function handling the actions will still need some way to tell what info to pass to the Action's function, though.

Share this post


Link to post
Share on other sites
When using the function, I will need to check what it points to first and then pass it.

Or I could just use an enumeration for each function and then use a switch statement for them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement