Invalid use of member (did you forget the '&' ?)
Dec 17, 2010 at 11:32am UTC
I've run into a problem creating a C++ class.
I'm trying to write something based on this...
http://www.airplaysdk.com/docs.php#/api/api/ExampleS3EPointerMulti.html
The problem I'm having concerns the callback functions passed as parameters to the s3ePointerRegister(), and s3ePointerUnRegister() methods.
On each of these lines, I can a compilation error:-
"Invalid use of member (did you forget the '&' ?)"
My relevant part of my .cpp file looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
void TouchHandler::registerListeners() {
gMultiTouch = s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE);
if (gMultiTouch) {
s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)multiTouchHandler, NULL);
s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)multiTouchMotionHandler, NULL);
}
else {
s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)touchHandler, NULL);
s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)touchMotionHandler, NULL);
}
}
void TouchHandler::unregisterListeners() {
if (gMultiTouch) {
s3ePointerUnRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)multiTouchHandler);
s3ePointerUnRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)multiTouchMotionHandler);
}
else {
s3ePointerUnRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)touchHandler);
s3ePointerUnRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)touchMotionHandler);
}
}
I investigated the definitions of s3ePointerRegister() and s3ePointerUnRegister(), although I don't want to change anything that side of the API. It looks like this:-
1 2 3 4 5 6 7
//blah
typedef int32 (*s3eCallback) (void * systemData, void * userData);
//blah blah blah
S3E_API s3eResult s3ePointerRegister(s3ePointerCallback cbid, s3eCallback fn, void * userData);
//blah
S3E_API s3eResult s3ePointerUnRegister(s3ePointerCallback cbid, s3eCallback fn);
//...
So, how can I get around the "Invalid use..." syntax error?
Dec 17, 2010 at 4:10pm UTC
Why are you casting?
What is the signature of multiTouchHandler, multiTouchMotionHandler, touchHandler and touchMotionHandler?
Dec 17, 2010 at 5:02pm UTC
Casting because s3ePointerRegister() and s3ePointerUnRegister() expect an s3eCallback parameter... and also because the example did this, and the example worked.
But sorry, yes I should have provided the signature of the callback methods. My .h file looks like this:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#ifndef _TOUCH_HANDLER_H
#define _TOUCH_HANDLER_H
#include "s3e.h"
class TouchHandler {
public :
#define MAX_TOUCHES 10
struct CTouch {
int32 x;
int32 y;
bool active;
int32 id;
};
typedef CTouch CTouchArray [MAX_TOUCHES];
TouchHandler();
virtual ~TouchHandler();
CTouchArray* getTouches();
protected :
CTouchArray gTouches;
bool gMultiTouch;
CTouch* getTouch(int32 id);
void multiTouchHandler(s3ePointerTouchEvent* event);
void multiTouchMotionHandler(s3ePointerTouchMotionEvent* event);
void touchHandler(s3ePointerEvent* event);
void touchMotionHandler(s3ePointerMotionEvent* event);
void registerListeners();
void unregisterListeners();
};
#endif
Dec 18, 2010 at 12:26am UTC
You're trying to pass in member functions. You can only pass in static member functions as member functions get passed a this pointer, which you're not doing.
In C++, if you have to cast, you really need to stop and think if what you're doing is correct. In this case, you are not.
I would imagine you'll need something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
class TouchHandler {
protected :
void multiTouchMotionHandler(s3ePointerTouchMotionEvent* event);
void registerListeners()
{
s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, multiTouchStaticHandler, this );
}
void unregisterListeners()
{
s3ePointerUnRegister(S3E_POINTER_TOUCH_EVENT, multiTouchStaticHandler);
}
private :
static void multiTouchMotionStaticHandler(void *systemData, void *userData)
{
if (TouchHandler* pHandler = reinterpret_cast <TouchHandler*>(userData))
{
pHandler->multiTouchMotionHandler(reinterpret_cast <s3ePointerTouchMotionEvent*>(systemData));
}
}
};
Last edited on Dec 18, 2010 at 12:51am UTC
Topic archived. No new replies allowed.