Please help...

  • Thread starter Thread starter Girish NS
  • Start date Start date
G

Girish NS

Hi,

Can anyone tell me

LRESULT (CWnd::*m_pMakeHypo)(int);

what's the meaning of this expression?

Thanks,

Girish.
 
This defines a member variable of CWnd class which is a pointer to a
function taking an int parameter and returning an LRESULT. It could be a
function like this:

LRESULT SomeFunction(int i);

It is likely a static member. If this is the case and you have this in .cpp
file, this would be the instantiation of the static member.
 
Almost.

This defines a variable named 'm_pMakeHypo' of type "pointer to function
member of CWnd that takes (int) and returns LRESULT".

Whether this declaration is also a definition depends on exactly where it
appears. Most often, functions accessed though pointer-to-member are not
static function, since these can be accessed more simply using an ordinary
function pointer.

Whether this variable is a member of CWnd depends entirely on where the
declaration appears. Only if this declaration is within the definition of
the CWnd class does it define a member of CWnd.

-cd
 
That's why you are a VC++ MVP and I am - Media Center :-)
Shame on me and thank you for correcting me. This has occured to me as a
possibiity, but I was too lazy to go and check. Fact is that I'm so acutely
uncomfortable with function pointer type syntax that I always write a
typedef even if I only use it once.
 
Hi,

Thanks a lot for your help...

Girish.
Alex Feinman said:
This defines a member variable of CWnd class which is a pointer to a
function taking an int parameter and returning an LRESULT. It could be a
function like this:

LRESULT SomeFunction(int i);

It is likely a static member. If this is the case and you have this in ..cpp
file, this would be the instantiation of the static member.
 
Hi,

Thanks a lot for your help.

Girish.
Carl Daniel said:
Almost.

This defines a variable named 'm_pMakeHypo' of type "pointer to function
member of CWnd that takes (int) and returns LRESULT".

Whether this declaration is also a definition depends on exactly where it
appears. Most often, functions accessed though pointer-to-member are not
static function, since these can be accessed more simply using an ordinary
function pointer.

Whether this variable is a member of CWnd depends entirely on where the
declaration appears. Only if this declaration is within the definition of
the CWnd class does it define a member of CWnd.

-cd
 
Carl Daniel said:
Almost.

Most often, functions accessed though pointer-to-member are not
static function, since these can be accessed more simply using an ordinary
function pointer.

Almost. :-)

Static member functions _cannot_ be pointed to by pointers-
to-member-functions. The type of "&foo::bar", where "bar" is
a static member function of "foo", is an ordinary function
pointer, not a pointer-to-member-function, and there is no
conversion from an ordinary function pointer type to a
pointer-to-member-function type. I guess that means that
"most often" == "always"? :-)

-- William M. Miller
 
Functions accessed through pointer-to-member NEVER are static functions.

By the way, there is little known feature of C++, related to typedefed
functions.
If you define a function typedef:

typedef int FunctionType(void * arg);

You can use FunctionType to declare functions, like:

FunctionType Function1;
FunctionType Function2;
FunctionType *pFunction2; // pointer to function

etc. This construct is also likely to work in C.

If you declare those Function1 and Function2 in a class declaration:

class Class
{
FunctionType Function1;
FunctionType Function2;
};

these become non-static member functions.

There is an example in the standard (which shows limitations if the function
typedef is CV qualified):

typedef int FIC(int) const;
FIC f; // ill-formed: does not declare a member function
struct S {
FIC f; // OK
};
FIC S::*pm = &S::f; // OK

The standard doesn't say, though, how

FIC *pf;

would be interpreted inside class declaration.
 
Hi,

Thanx a lot for your valuable help.

Girish.
Alex Feinman said:
This defines a member variable of CWnd class which is a pointer to a
function taking an int parameter and returning an LRESULT. It could be a
function like this:

LRESULT SomeFunction(int i);

It is likely a static member. If this is the case and you have this in ..cpp
file, this would be the instantiation of the static member.
 
Hi,

Thanx a lot for your valuable help.

Girish.
Carl Daniel said:
Almost.

This defines a variable named 'm_pMakeHypo' of type "pointer to function
member of CWnd that takes (int) and returns LRESULT".

Whether this declaration is also a definition depends on exactly where it
appears. Most often, functions accessed though pointer-to-member are not
static function, since these can be accessed more simply using an ordinary
function pointer.

Whether this variable is a member of CWnd depends entirely on where the
declaration appears. Only if this declaration is within the definition of
the CWnd class does it define a member of CWnd.

-cd
 
Back
Top