Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit namespace qualifier is missing in macro definitions in CCObject.h #867

Closed
qbit86 opened this issue Apr 25, 2012 · 4 comments
Closed

Comments

@qbit86
Copy link

qbit86 commented Apr 25, 2012

Macro definitions should involve full namespace qualification (to be independent from usage context).

Expected:
#define schedule_selector(_SELECTOR) (::cocos2d::SEL_SCHEDULE)(&_SELECTOR)
or even preferable
#define schedule_selector(_SELECTOR) static_cast<::cocos2d::SEL_SCHEDULE>(&_SELECTOR)

Actual:
#define schedule_selector(_SELECTOR) (SEL_SCHEDULE)(&_SELECTOR)

The latter causes a compilation error if namespace cocos2d is not imported in user's code (to prevent namespace pollution for example):

// No using's.
auto const f = schedule_selector(DemoScene::Update); // error C2065: 'SEL_SCHEDULE' : undeclared identifier
@minggo
Copy link
Contributor

minggo commented Apr 25, 2012

All engine codes are qualified in name space cocos2d, you should use the name space to invoke any engine codes. So is it needed?

@qbit86
Copy link
Author

qbit86 commented Apr 25, 2012

All engine codes are qualified in name space cocos2d

After expanding macros in user code their content is NOT in predictable context or namespace.

you should use the name space to invoke any engine codes.

I cannot qualify the macro with namespace. I forced to import namespace, because i cannot say something like that

// Pseudocode:
auto const f =  cocos2d::schedule_selector(DemoScene::Update);

So is it needed?

I think the opposite question should be asked :) Is there any reason to NOT specify namepace in macro definition? Well-known libraries (Boost for example) do always specify full “namespace path” to their identifiers in macro definitions. It's written once, and used frequently, so why not to do this?

@minggo
Copy link
Contributor

minggo commented Apr 25, 2012

Yeap, you are right.
http://www.cocos2d-x.org/issues/1192 is created for it.

Thank you.

@donaldalanmorrison
Copy link
Contributor

Cross-reference #1192 no longer exists. @minggo Are all the "using namespace _;" macros fixed?

@minggo minggo closed this as completed Aug 22, 2013
WenhaiLin pushed a commit to WenhaiLin/cocos2d-x that referenced this issue Oct 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants