Error:(75, 24) error: 'cocos2d::Node' is an inaccessible base of 'mLayerColor'

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

try this:

auto mHud = LayerColor::create(Color4B(255,255,255,255),100,100); // 100 is width and height
this->addChild(mHud);

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.

class mLayerColor: cocos2d::LayerColor {

public:

    mLayerColor();
    ~mLayerColor();
    static mLayerColor* createLayer(cocos2d::Color4B color, cocos2d::Node* parent);
    virtual bool init(cocos2d::Color4B color);

    void setParent(cocos2d::Node* parent);


private:
    cocos2d::RefPtr<cocos2d::ui::Button> _btn_login;
    cocos2d::RefPtr<cocos2d::Node> _parent_ref;

};

and the implementation is:

#include "mLayerColor.h"

USING_NS_CC;

mLayerColor::mLayerColor() {}

mLayerColor::~mLayerColor() {}

mLayerColor* mLayerColor::createLayer(Color4B color, Node* parent)
{
    mLayerColor*a = new MainArenaHUD;

    a->setContentSize(Size(1, 1));
    a->setAnchorPoint(Vec2(0, 0));
    if (a && a->init(color))
    {
        a->autorelease();
        a->setParent(parent);
        return a;
    }
    CC_SAFE_DELETE(a);
    return NULL;
}

bool mLayerColor::init(cocos2d::Color4B color)
{
    if (!LayerColor::initWithColor(Color4B(255, 0, 0, 0))) return false;
    return true;
}

void mLayerColor::setParent(cocos2d::Node* parent)
{
    this->_parent_ref = parent;
}

@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 :smiley: