Calling base class methods in MFC
When learning MFC you often see code like this:
void MyWindow::OnSysCommand(UINT id, LPARAM lParam)
{
CWnd::OnSysCommand(id, lParam);
}
It is always the same parameters that are given in the call to the base class as those you were given in the first place.
But isn''t this making it harder on yourself to try to do this? In the MFC documentation it is often stated that the call to base class methods will use original message parameters - not the one you give it. In effect the arguments you give is ignored - or so they say.
But why then bother to keep the arguments the same. I could just make a call like this:
CWnd::OnSysCommand(0,0);
And forget all about it. I could change the arguments I revieved in the handler to suit my own purposes and if I changed the names and wouldn''t have to do multiple updates.
So why are people using the style above and not just the one at the bottom? Can the code break? Is it just bad style?
In my case I have to do a lot of processing before I decide to call the base class method. So if I just can forget all about the arguments and put in some default values may code would be both cleaner and faster.
Jacob Marner
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Please. Will somebody consider answering this?
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Doing what you suggest will "break your code". There''s nothing mystical about MFC - it''s just C++. And like any C or C++ function MFC base class methods will use whatever arguments you pass to them. If you modify those arguments you will modify the behaviour of your class. If you follow your own suggestion you will simply introduce a whole bunch of bugs in your program. Don''t do it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement