cocos2d/cocos2d-x — Issue #674: Naming clash in CCTouchDispatcher.cpp
Author: Qbit86
Created: 2012-01-12 08:31:11+00:00
State: open

There is a problem with less() function:

static bool less(const cocos2d::CCTouchHandler *p1, const cocos2d::CCTouchHandler *p2)
{
return ((cocos2d::CCTouchHandler*)p1)->getPriority() < ((cocos2d::CCTouchHandler*)p2)->getPriority();
}

In some circumstances (Mac OS X, XCode, order of #include's) one can get an error here (line 304):

void CCTouchDispatcher::rearrangeHandlers(CCMutableArray *pArray)
{
std::sort(pArray->begin(), pArray->end(), less);
}

Probably, it is due to disambiguation with std::less, which is accessible via ADL (Koenig lookup) [1] or something like that.

Possible solution:

namespace { namespace details { // [2]

bool less(const cocos2d::CCTouchHandler *p1, const cocos2d::CCTouchHandler *p2)
{
return ((cocos2d::CCTouchHandler*)p1)->getPriority() < ((cocos2d::CCTouchHandler*)p2)->getPriority();
}

} }

void CCTouchDispatcher::rearrangeHandlers(CCMutableArray *pArray)
{
std::sort(pArray->begin(), pArray->end(), details::less);
}

[1] http://en.wikipedia.org/wiki/Argument-dependent_name_lookup
[2] http://stackoverflow.com/questions/154469/unnamed-anonymous-namespaces-vs-static-functions