Projects > cpp > Issues > Refactor #2347

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

Macros like CC_KEYBOARD_SUPPORT should not be in header file

Refactor #2347 [Closed]
dumganhar 2013-07-01 08:14 . Updated over 3 years ago

Refers to https://groups.google.com/forum/\#!topic/cocos2d-js-devel/HEJKYWXNXRU
Thanks Riq.

One thing that we should try to avoid, is adding “#ifdef XXXX” in the class definition.
The #ifdef should cover the whole class, or should be avoided.

Example:

// DANGER: Could lead to a potential bug very difficult to find.
class Node {
void addChild();
void removeChild();
#ifdef SUPPORT_FOR_XXX
void insertChild();
#endif
}

// BETTER: class interface (and vtable) is the same interface.
class Node {
void addChild();
void removeChild();
void insertChild();
}

Node::insertChild()
{
#ifdef SUPPORT_FOR_XXX
do….
#else
ASSERT (false, "NOT IMPLEMENTED");
#endif
}

The problem is when the “cocos2d” project is compiled as an static or dynamic lib with certain macro preprocessor, and the game is compiled with a different ones.

dumganhar 2013-07-01 08:14
  • Tracker changed from Bug to Refactor
dumganhar 2013-07-02 00:38
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset commit:c720a9e0af109292fbbf896ed90c2c65de2ccb23.

Atom PDF

Status:Closed
Start date:2013-07-01
Priority:Normal
Due date:
Assignee:dumganhar
% Done:

100%

Category:all
Target version:3.0-alpha0-pre

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.