why the init method?

why the init method?
0.0 0


Was curious why the ‘init’ method was added to the classes to mimic ObjC since C*+ has the constructors, was that really needed? Can’t all ‘init’ processing be done on a normal C*+ constructor?


I believe it has something to do with constructor failure of base classes when sitting inside a derived class. By avoiding function calls to Super::function() in the constructor it is safer code.


Because the constructor of c*+ does not have a return value. We can not judge whether our classes are constructed successfully if putting initialization into c*+ constructor function.


Hi, I was wondering about this too and the answers make perfect sense. However, how does dependency injection work with this scheme? For example I want my Player Class to store a reference to the Level Class, so that it can notify the level if necessary. The only way I can think of is to add a parametrized init function to the class. The only problem with that is, is that if you forget to call it all hell will break lose.
Your thoughts?


so Construcotr is just for allocation, and init function is for initialization ? is that right? and another one, what is the main effect of a static constructor in cocos2d-x?


In what situation that i should have a static constructor?