Hi cocos2dx,
I have a question about the virtual bool init
function which I see in all sample projects and in the example code itself. I’m new in the coocs2dx framework but I worked with C++ before. I have the following code:
class MyLayer : public Layer{
MyReference& ref;
public:
MyLayer(MyReference& ref);
virtual bool init();
};
As you can see I have a member variable with a reference. Unfortunantely I can’t use the init
function like normal cause I have to intialized the ref in the constructor like so:
MyLayer::MyLayer(MyReference& ref):
ref(ref)
{}
I understand the idea behind the init
function. Cause the constructor does not return any value if the initalization was successful or not. But when I build up controls in MainMenu for example. I don’t need the init
function cause I know it will not fail (in my example).
I just want to programm in the style like cocos2dx would recommend it. So is it mandatory to have the virtual bool init function
? And if yes is there any possibilty to have a member reference?
Greetings