struct Message
{
virtual ~Message(void) {}
};
// methods not referred to are omitted
struct IMessageObserver
{
virtual void notify(const Message& msg) = 0;
virtual void notify2(const Message& msg, void* data) = 0;
};
struct MessageWithoutData
: public IMessage
{
} MSG_NO_DATA; // no members and this instance mean I can compare (msg == MSG_NO_DATA) to determine what notification I've been given
struct MessageWithData
: public IMessage
{
MessageWithData(int newValue)
: value(newValue)
{}
int value;
} // can't do a straightforward comparison in notify() now - RTTI instead?
// the example notifications
void doANotification(IMessageObserver& observer)
{
int newValue(24);
// should I construct with the data?
observer.notify(MessageWithData(newValue));
// or pass the data separately
observer.notify2(MSG_NO_DATA, &newValue);
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE