【发布时间】:2014-04-15 08:38:51
【问题描述】:
我有很多来自 CCNode 子类的节点,其中一些具有函数 ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)。
现在我的问题是是否可以使用 SFINAE 检查他们是否拥有这个特定功能。
我试图在该线程的帮助下使其工作:Is it possible to write a template to check for a function's existence? 但我做不到。
这是我所拥有的:
template <typename T>
class hasMethodCCTouchBegan
{
typedef char yes;
typedef long no;
template <typename C> static yes test( decltype(&C::ccTouchBegan) ) ;
template <typename C> static no test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(yes) };
};
老实说,我不知道该怎么做。
【问题讨论】:
标签: c++ templates cocos2d-x sfinae