Original Post
hi all,
I've searched these forums and found this tutorial: functor.html while trying to get function pointers working... but for some reason it really doesn't seem to want to work..
template< class _C >
class MY_MouseEventHandler {
private:
bool ( _C::*fPtr )( int b, int x, int y );
_C* thisPtr;
public:
void Call( int b, int x, int y ) {
(*thisPtr.*fPtr)(b,x,y);
}
MY_MouseEventHandler( _C* classPtr, bool ( _C::*functionPtr )( int b, int x, int y ) ) {
fPtr = functionPtr;
thisPtr = classPtr;
}
}; I use the above code as my functor - I know most people use a base class, but for this particular job that seemed to be overkill.. This code compiles with no complaints, and is a near-enough copy of the code from the above link.
class TEST_A {
public:
void init( ) { };
bool MouseDown( int b, int x, int y ) { };
bool MouseUp( int b, int x, int y ) { };
bool MouseMove( int b, int x, int y ) { };
}; I use this class as a simple test - to represent a set of functions that might receive the callback events..
I then, in my main() have this code - the stuff that actually uses the two previous classes:
TEST_A t_a; t_a.MouseDown( 1, 2, 3 ); t_a.MouseMove( 4, 5, 6 ); t_a.MouseUp( 7, 8, 9 ); MY_MouseEventHandler< TEST_A > meh( &t_a, &t_a::MouseDown );Thing is, it wont compile - I get an error on the last line: error C2510: 't_a' : left of '::' must be a class/struct/union okay, I know what the error means... but I don't get why it won't allow the above code?! it's really confusing me. The code in the aforementioned tutorial does a nearly identical thing. Any ideas? cheers, Jack [edited by - Jollyjeffers on January 29, 2004 7:29:59 PM] [edited by - Jollyjeffers on January 29, 2004 7:30:14 PM] [edited by - Jollyjeffers on January 29, 2004 7:31:11 PM]