how this is valid??
If PreTranslateMessage() is not static function then how can we call
it by this way (i.e. ClassName::FunctionName)??
If C++ class 'Derived' derives from 'Base', it is ordinary C++ syntax to
call Base::DoSomething() from Derived::DoSomething(). There is no constraint
for DoSomething method to be static.
(The compiler can happily pass the 'this' pointer as hidden parameter as
usual.)
Giovanni
(Not at all MFC question, BTW. Try http://groups.google.com/group/comp.lang.c++.moderated/topics
for more involved crowd).
I would guess the most important reason that this is allowed really is
inheritance.
That said, why you think it's important that language prevents you
from using fully-qualified function name? It's the same call, just
longer to type (but, important with inheritance).
Note that you can also do:
class Type
{
public:
static void StaticFunc() {}
void Func() {}
};
Type var;
var.StaticFunc(); // !!! works not with class name, but class instance
var.Type::Func(); // !!! works, too
Goran.
CWnd::PreTranslateMessage is a *virtual* method. RTFM. Note that if you have class A,
from which you derive class B, from which you derive class C, and in C:something you call
the superclass A:something, this is *probably* wrong; you should have called B:something.
You can avoid this error by using the Microsoft extension __super, e.g., calling
__super::something, so if you later introduce class B between A and C (C was formerly
derived from A), and forget to change the calls in C to call its correct superclass, this
saves you. But it can also do you in; see the documentation for __super for an
interesting case.
Message maps are a cheat that let you get virtual methods without massive vtables.
Unfortunately, they aren't quite right, and don't quite simulate virtual methods. In
particular, if you call the base class from a derived message map, it does not use the
arguments you pass (which would have made sense in an OO system) but instead uses the
parameters from the original message (which is actually incorrect behavior; it is just
what MFC does, due to terminal brain damage in the original design to make it "efficient";
that is, Unixitis infected them. In Unix, the philosophy was "we don't care if it is
correct, as long as it is small and fast")
joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Note also that PreTranslateMessage is often abused and used inappropriately, for example,
to simulate Petzold-style handlers, or because the programmer really doesn't understand
the message map. Nearly *all* uses I've seen of PreTranslateMessage are incorrect; it is
used in very rare contexts, such as handling F1 help. There are many correct ways to use
it, but you'd have to explain why you are using it before I'd believe it is being used
correctly.
joe
On Wed, 25 Nov 2009 00:52:22 -0800 (PST), rahul <hyra...@gmail.com> wrote: