🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++.moderated
Article #4

How to initialize a static member of a pointer to member function?

#4
From: Jin J. Chou
Date: Thu, 14 Dec 1995 20:24
42 lines
1761 bytes
X-Original-Date: 14 Dec 1995 17:45:37 GMT

For those who are experts on C++, what is the syntax to
initialize a static member of a class while the member
is a pointer to a member function?  Here is an example:

class A {
public:
  // The intent is to to have stmemfun to be a static member
  // of A while the member is a pointer to a member function of A.
  // Is this declaration right?
  static int (A::*stmemfun)(int) const;

public:
  A(int inita) : aa(inita) {}
  int aa;
  int getaaplus(int b) const {return aa+b; }
  
  int help(int b) const { return (this ->* stmemfun)(b); }
};

// This would compile but stmemfun is a global not the static member of A
// int (A::*stmemfun)(int) const = &A::getaaplus;

// This does not compile on SGI C++ 4.0 with patch556
int A::((A::*stmemfun)(int) const) = &A::getaaplus;

void main() {
  A aA(5);
  // I want dd to be 14
  int dd = aA.help(9);
}

Jin Chou
--------
jchou@nas.nasa.gov


    [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
    [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
    [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
    [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
Technical Details
Message-ID: <4aq153$1ht@netlab.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!library.erc.clarkson.edu!rpi!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!library.erc.clarkson.edu!rpi!not-for-mail
From: jchou@nas.nasa.gov (Jin J. Chou)
Newsgroups: comp.lang.c++.moderated,comp.lang.c++
Subject: How to initialize a static member of a pointer to member function?
Date: 14 Dec 1995 20:24:03 -0000
Organization: NAS, NASA Ames Research Center, Moffett Field, California
Sender: cppmods@netlab.cs.rpi.edu
Approved: Dietmar.Kuehl@uni-konstanz.de
Message-ID: <4aq153$1ht@netlab.cs.rpi.edu>
NNTP-Posting-Host: netlab.cs.rpi.edu