【发布时间】:2015-01-20 19:11:52
【问题描述】:
我为phidgets C 库制作了一个 C++ 包装器,我目前有一个用于通用 Phidget 设备的PhidgetDevice.h,这是标题:
#ifndef PHIDGET_DEVICE_H
#define PHIDGET_DEVICE_H
#include <phidget21.h>
#include <vector>
#include <iostream>
#include <string>
#define COMMON_IO_EVENT_CALLBACK(name) int CCONV name(CPhidgetHandle phid, void* userPtr)
#define ERROR_EVENT_CALLBACK(name) int CCONV name(CPhidgetHandle phid, void *userPtr, int errorCode, const char *errorString)
enum DeviceType
{
DEVICE_NULL,
DEVICE_KIT,
DEVICE_TEMPERATURE_SENSOR,
DEVICE_MOTION_SENSOR
};
class PhidgetDevice /* base class for every phidget device*/
{
public:
PhidgetDevice() : m_type(DEVICE_NULL) {}
explicit PhidgetDevice(DeviceType type) : m_type(type) {}
void SetType(DeviceType type) { m_type = type; }
virtual DeviceType GetType() { return m_type; }
virtual void CCONV SetAttachHandler(CPhidgetHandle IFK, int(__stdcall * callback) (CPhidgetHandle phid, void *userPtr), void *userptr) { CPhidget_set_OnAttach_Handler(IFK, callback, userptr); }
virtual void CCONV SetDetachHandler(CPhidgetHandle handle, int(__stdcall * callback) (CPhidgetHandle phid, void* userPtr), void * userptr) { CPhidget_set_OnDetach_Handler(handle, callback, userptr); }
virtual void CCONV SetErrorHandler(CPhidgetHandle handle, int(__stdcall * callback) (CPhidgetHandle phid, void* userPtr, int errorCode, const char *errorString), void * userptr) { CPhidget_set_OnError_Handler(handle, callback, userptr); }
protected:
DeviceType m_type;
};
#endif
这使得凌乱的 C Phidget 函数看起来好多了。
现在,这在 Visual Studio 2013 上编译得很好,但是当我尝试使用 g++ 4.8 编译它时,包括-std=c++11 我得到了:
PhidgetDevice.h:34:72: 错误:在‘*’令牌虚拟之前预期‘)’ 无效 CCONV SetAttachHandler(CPhidgetHandle IFK,int(__stdcall * 回调) (CPhidgetHandle phid, void *userPtr), void *userptr) { CPhidget_set_OnAttach_Handler(IFK, 回调, userptr); }
还有更多,不过都在抱怨函数指针。
我的函数指针有什么问题?
【问题讨论】: