VS7.1: No member function pointer call possible?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Axel Dahmen

    #1

    VS7.1: No member function pointer call possible?

    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


  • Igor Tandetnik

    #2
    Re: VS7.1: No member function pointer call possible?

    "Axel Dahmen" <NoSpam@NoOneKn ows.de> wrote in message
    news:OTdDZ4o5DH A.2404@TK2MSFTN GP11.phx.gbl...[color=blue]
    > I can't get to compile the following:
    >
    >
    > struct A
    > {
    > A(void);
    > bool fn(void);
    > bool (A::*pfnc)(void );
    > };
    >
    >
    > A::A(void) : pfnc(fn) {}[/color]

    Should be

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

    Should be

    (a.*(a.pfnc))() ;
    [color=blue]
    > return 0;
    > }[/color]

    --
    With best wishes,
    Igor Tandetnik

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


    Comment

    • Doug Harrison [MVP]

      #3
      Re: VS7.1: No member function pointer call possible?

      Axel Dahmen wrote:
      [color=blue]
      >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?[/color]

      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".

      --
      Doug Harrison
      Microsoft MVP - Visual C++

      Comment

      Working...