Wouldn't that just fail to compile, since the const version hides the non-const version, and the const version can't be called with the non-const pointer?Only then the const version is called
Wouldn't that just fail to compile, since the const version hides the non-const version, and the const version can't be called with the non-const pointer?Only then the const version is called
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Not really. The cast casts to a non-const type, and you try to call a const function on it. It should just fail to compile, and if it doesn't, you've got a really weird compiler.The cast takes care of the not compiling part.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
1. according to your design handleEvents( EventHandler *eh ) seems to take a polymorphic argument and you will invoke the handleEvent() method on that EventHandler* or EventHandler* Derived Object. So making handleEvent private in a derived Class vreaks your own design.
2. when you are casting (void)e you are not changing type of MyEventHandler::e to void rather you are either returning a copy of e which holds the same data of e but type void (which happens here), or returning the value of e in void format.
Other than reiterating various known facts and merging them with meaningless ranting, the initial question was "why?" not "what?"
Did you put the excessively-whiny-about-everything-because-i-cant-avoid-not-designing-my-classes-poorly flag? I think its a gcc thing.
I always -Wall myself
At this point I guess, although the standard is a bit flaky in this regard, it's not a flaw in the language so much as in compiler design. Just another thing to add to the mailing list...
Fair enough. I am sure Stroustrup will send you back a personally autographed punch card from the first IBM mainframe he ever programmed.