Hi,
About two weeks ago (or so) I posted here that I was having problems
with getting a member function pointer to point to a member function
without giving me grief. I've gone to trying this on a trial program
that I will post below in its entirety. I just can't get it right and
although I've tried the suggestions given to me from the other
posting, I'm still doing something wrong. So, here's my test program:
#include <iostream>
class base {
int somedata;
public:
base();
int GetData() {
return somedata;
}
int (base::*ptrMemFunc)();
};
base::base() : somedata(5), ptrMemFunc(&base::GetData)
{}
// this one's only in here to make sure I remembered how to use
function pointers
int AnInt() {
return 5;
}
int main( ) {
base b;
int (*pAnInt)() = AnInt;
std::cout << pAnInt() << std::endl;
b.ptrMemFunc();
return 0;
}
Now, my compiler (GNU 3.3.3) is giving me these errors:
(Note: as the code is above)
foo.cxx: In function `int main()':
foo.cxx:34: error: call to non-function `base::ptrMemFunc'
(Note: if I change line 34 to having a * in front of ptrMemFunc I get
this error:)
foo.cxx: In function `int main()':
foo.cxx:34: error: `ptrMemFunc' undeclared (first use this function)
foo.cxx:34: error: (Each undeclared identifier is re****ted only once
for each
function it appears in.)
In the second case, I do not understand at all why it says that
ptrMemFunc is undeclared. It's right there in the class definition.
So, how do I get a class member, that is a function pointer, point to
another member function of that class, and the use that pointer to
reference these functions in other parts of the code that I'm trying
to?
Thanks, and forgive my confusion.
Andy


|