I am trying to add a LayerColor to another LayerColor object with addChild:
auto mHud = mLayerColor::createLayer(Color4B(255,255,255,255),this); // this line compiles fine
this->addChild(mHud); // this line causes compile time error
But in the second line above I get the compile time error: Error:(75, 24) error: 'cocos2d::Node' is an inaccessible base of 'mLayerColor'
Both the layer i am trying to create and add, and the one adding that layer (this->addChild), are implemented almost identical. Couldnt find the source of the problem but if someone knows why this could fire I might be able to atleast track it.
Thanks
Your code works as expected, since its using the LayerColor from cocos2dx library. But mLayerColor is actually a class inherited from LayerColor and I need to add that since I have customized it to my needs.
@Ams I believe you forgot a single keyword “public”.
class mLayerColor: public cocos2d::LayerColor {
This keyword will inform the compiler that mLayerColor will inherit not just the private but public stuff as well.
Also, off-topic, I believe it’s good practice to make your destructor a virtual one.
virtual ~mLayerColor();
Doing so will make sure that the destructor of your superclass will be called. This is very important especially if your parent class does something for cleaning i.e. reference counting
@macmoy Thanks for the reply, YES! that is the problem. So far I have more than 10 layer classes in my project all working fine and I was loosing my mind over why on earth would this one disobey! lol
You cant believe how many hours I wasted on this… and the fact that the compiler ignores it (seems this “:” in C++ has other meanings too) made it even harder to notice, I checked absolutely everything, but the only unsuspecting place was the header