VS7.1: No member function pointer call possible?

  • Thread starter Thread starter Axel Dahmen
  • Start date Start date
A

Axel Dahmen

Hi,

I can't get to compile the following:


struct A
{
A(void);
bool fn(void);
bool (A::*pfnc)(void);
};


A::A(void) : pfnc(fn) {}


bool A::fn(void) {return true;}


int _tmain(int argc, _TCHAR* argv[])
{
A a;
(a.*pfnc)(); // *** error: 'pfnc': undeclared identifier ***
return 0;
}

Is it me?? This ought to be correct C++ syntax. What am I doing wrong?

TIA,
Axel Dahmen
 
Axel Dahmen said:
I can't get to compile the following:


struct A
{
A(void);
bool fn(void);
bool (A::*pfnc)(void);
};


A::A(void) : pfnc(fn) {}

Should be

A::A(void) : pfnc(&A::fn) {}
int _tmain(int argc, _TCHAR* argv[])
{
A a;
(a.*pfnc)(); // *** error: 'pfnc': undeclared identifier
***

Should be

(a.*(a.pfnc))();
return 0;
}

--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
 
Axel said:
Hi,

I can't get to compile the following:


struct A
{
A(void);
bool fn(void);
bool (A::*pfnc)(void);
};


A::A(void) : pfnc(fn) {}


bool A::fn(void) {return true;}


int _tmain(int argc, _TCHAR* argv[])
{
A a;
(a.*pfnc)(); // *** error: 'pfnc': undeclared identifier ***
return 0;
}

Is it me?? This ought to be correct C++ syntax. What am I doing wrong?

Try:

(a.*a.pfnc)();

P.S. For functions which have no parameters, it's conventional in C++ to
omit the "void", because in C++, an empty parameter list means "void".
 
Back
Top