Projects > cpp > Issues > Refactor #2517

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

Create Issue on Github

C++11 approach: Update all test cases. Use @auto@ for local variables

Refactor #2517 [Closed]
ricardo 2013-08-09 23:50 . Updated over 3 years ago

All test cases and samples should update its local variables to use auto, at least for cocos2d object pointers.
Example:

void someFunction() {
  // This is a local variable, but it is not a pointer to a cocos2d object.
  // There is no need to convert it to "auto"
  int i=0;

  // This is a local variable AND it is not a pointer to a cocos2d object.
  // So, it MUST be converted to "auto"
  Node *node = layer->getChildByTag(10);

  // This is a local variable AND it is not a pointer to a cocos2d object.
  // So, it MUST be converted to "auto"
  Sprite *sprite = Sprite::create("sprite.png");

  // This is a local variable AND it is not a pointer to a cocos2d object.
  // So, it MUST be converted to "auto"
  Action *action = MoveBy::create(...);

  // This is a local variable AND it is not a pointer to a cocos2d object.
  // So, it MUST be converted to "auto"
  Action *copy = action->clone();
}

// The converted code should look like this:
void someFunction() {
  int i=0;
  auto node = layer->getChildByTag(10);
  auto sprite = Sprite::create("sprite.png");
  auto action = MoveBy::create(...);
  auto copy = action->clone();
}

The good thing about this change is that we a following a best practice, and that code will be compatible with the current API and the final API of v3.0

ricardo 2013-08-09 23:57
  • Target version set to 3.0-alpha0
ricardo 2013-08-10 00:26
  • Tracker changed from Bug to Refactor
  • Priority changed from Normal to High
ricardo 2013-08-10 16:10
  • Subject changed from Update all test cases: Use @auto@ for local variables to Hybrid approach: Update all test cases. Use @auto@ for local variables
walzer@cocos2d-x.org 2013-08-13 03:13
  • Subject changed from Hybrid approach: Update all test cases. Use @auto@ for local variables to C++11 approach: Update all test cases. Use @auto@ for local variables
  • Assignee set to zhangxm
zhangxm 2013-08-14 02:29
  • Assignee changed from zhangxm to boyu0
boyu0 2013-08-17 11:00
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset commit:ab65a87aae8d02a239c541c94f760caa3a07c307.

Atom PDF

Status:Closed
Start date:2013-08-09
Priority:High
Due date:
Assignee:boyu0
% Done:

100%

Category:all
Target version:3.0-alpha0

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