If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
I have two parts of my app that I want to keep seperate. When something important happens in one part, I want to notify the other with a message that can have very different payloads. I would create specialized payloads that inherit from AdditionalInfoPayloadBase and static_cast them depending on TChangeType if needed in every specialized page derived from PageBase.
What I have successfully done in other circumstances is this, but it seems a bit outdated or even dangerous:
Hi,
Could you give more details please?
Namely what type of change you are looking for?
What type of variable(s) will be changing?
Are you changing something inside the thread?
What I have in mind is something like the observer pattern, only without registering observers somewhere.
I have different kinds of pages inheriting from PageBase in a vector, there will be additional kinds of pages in the future. I want to notify every page of a possibly relevant change in other parts of the app, adding optional addition info payload i.e. a pointer or a wxPoint. Right now I am thinking of inheriting these additional info entities from AdditionalInfoPayloadBase. When a page has to react to a certain TChangeType, it has to static_cast the AdditionalInfoPayloadBase into the actual payload, maybe AdditionalInfoPayloadBaseWithPointer and that is what bothers me. The cast has to be correct and is a possible problem in the future. Every page has to do the correct cast associated with a certain TChangeType.
I thought about using a template, but maybe there is a more elegant way without casting? or something more error safe?
This has nothing to do with threads, everything happens within the main thread.
thank you!
use dynamic_cast<>. at least it will raise an exception if actual cast was wrong.
dynamic cast checks at runtime if pointer can be really cast to given type.