Thread View: comp.lang.c++.moderated
1 messages
1 total messages
Started by Jin J. Chou
Thu, 14 Dec 1995 20:24
How to initialize a static member of a pointer to member function?
Author: Jin J. Chou
Date: Thu, 14 Dec 1995 20:24
Date: Thu, 14 Dec 1995 20:24
42 lines
1761 bytes
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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads