Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • This answer leads me to think that this actually a fairly simple problem I'm stating ;-) This is actually exactly how I implemented the incoming message queue: a queue of base class shared pointers. Still the overhead of additional classes just to wrap another class into my response seems like something that can be done more efficiently? Excuse me for being so pigheaded, but I'd like to be absolutely sure I'm choosing the best solution. I really like to improve my C++ skills and I'm hoping to learn from the members here! Commented Apr 1, 2011 at 11:19
  • Also, how would I get the originating type back for the dynamic_cast? Would it be ugly to use the enum for this? Commented Apr 1, 2011 at 11:34
  • Yes, you don't have much choice other than passing some identifier (your enum) and a pointer to the data. This is how, for example, Windows' messaging system works. C++ is statically typed, so you can't store different types of objects in the same queue without also storing some data to identify what the object is, and then casting it. Commented Apr 1, 2011 at 11:47
  • Right I see, well I guess it makes sense. Since the other queue is implemented as this as well even more so. I'll take this approach. Thanks to you all! Commented Apr 1, 2011 at 12:22
  • @dauphic: for polymorphic messages, you can inherit from a base-message and upon receive always call the virtual function processMsg(), which can dispatch to the proper destination. So no enum or dynamic_cast is needed. Commented Apr 1, 2011 at 12:37