Coco2d-X equivalent of _myObject = [MyObject node]; ? (Semantic Issue: Assigning to 'MyObject *' from incompatible type 'cocos2d::CCNode *')

Hi !

I am new with Coco2d-X. I am trying to convert my Coco2d-iOS game to Coco2d-X…

iOS VERSION OF MY CODE:

MyObject.h file:

@interface MyObject : CCNode {
//CODE…
}

=> MyObject inherits from CCNode

Main.m file init" method)

*myObject = ;
=> everything works properly

C++ VERSION:
MyObject.h file:
class MyObject : public cocos2d::CCNode
{
}
=> MyObject inherits from CCNode
Main.cpp file method)
*myObject = MyObject::node();

=> returns the following error: “Semantic Issue: Assigning to ‘MyObject ’ from incompatible type ’cocos2d::CCNode’”

I don’t understand why as node() method exists in CCNode and MyObject inherits from CCNode.

Where is my error ?

Thanks !

class MyLayer : public CCLayer
{
    // ...
    LAYER_NODE_FUNC(MyLayer);  // notice this!
}

_myLayer = MyLayer::node();

You can refer to the definition of LAYER_NODE_FUNC(layer) in CCLayer.h, and SCENE_NODE_FUNC(scene) marco in CCScene.h
The reason is c*+ has no the same feature as “self” in objc. In objc, CCNode children and inherit node function, and use “self” pointed to the children themselves. But in c*+ we had to overload node() method in child node, and implement it manually.

Thanks it works !