USING_NS_CC in header file?

This is a quick question. I’ve seen many cocos2dx code were USING_NS_CC is only applied on the source files, not the header files. And I wonder if there is a reason not to use it directly in the header file.

R

It is the same as “using namespace cocos2d”. If you add “using namespace” to a header file it can unexpectedly change the meaning of code in any other files that include that header.

sure. I am aware of what USING_NS_CC. I use it in all my source files, I was just wondering why not use it directly in the header files.

The reasons to not use the directive “using namespace” in header files is not related to Cocos2d-x, and there is plenty of info online about why it’s bad practice.

It will most likely introduce name clashes, and result in ambiguous code errors when the compiler is attempting to resolve names of methods.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.