According to cocos2d-x source code macro is an equivalent of using namespace cocos2d
.
You can check it on your own in CCPlatformMacros.h in cocos2d-x repository:
#ifdef __cplusplus
#define NS_CC_BEGIN namespace cocos2d {
#define NS_CC_END }
#define USING_NS_CC using namespace cocos2d
#define NS_CC ::cocos2d
#else
#define NS_CC_BEGIN
#define NS_CC_END
#define USING_NS_CC
#define NS_CC
#endif
In response to @rene answer, I checked "Learning Cocos2d-x Game Development" from author Siddharth Shekar and the author is wrong.
Here is a link to that paragraph from this book, here is an image of the paragraph.
What he wrote wrong about USING_NS_CC
:
it doesn't "#include CCPlatformMacros.h
" and it doesn't load additional macros
To use it you need to include CCPlatformMacros.h
directly by adding
#include <cocos/CCPlatformMacros.h>
or indirectly by adding other header that contains it, e.g. #include <cocos2d.h>
.
it doesn't set the namespace to cocos2d
It includes all symbols from cocos2d
namespace, what makes that you can use cocos2d-x symbols without pointing the right cocos2d::
.
To set a namespace cocos2d
for you symbols you should use
namespace cocos2d
{
// some declarations/definitions
}
or equivalent:
NS_CC_BEGIN
// some declarations/definitions
NS_CC_END
But remember that adding your own symbols to external library is strongly not recommended.