Inheritance - Triple

Curious Question

I have Base Class A

B inherits from A

C inherits from B

But seems C cant access A members which are all protected, even making them public didn’t work

Why is that

Thanks :slight_smile:

You need to post a code example. You could be privately inheriting A in class B, or you may not be accessing A’s members in C. There’s no way to know from your example.

So I should be able inherit right ? I’m going to remake example as I back tracked as wouldn’t work. Back in few minutes

CLASS A BELOW

#ifndef GAME_OBJECT_H
#define GAME_OBJECT_H
#include "cocos2d.h"
class GameObject
{
	public:

		virtual cocos2d::Sprite* getSprite() = 0;
		virtual void animate() = 0;

	protected:

		GameObject(){};
		virtual ~GameObject(){};
		cocos2d::Sprite* sprite;
		float TIscale = 1.7068;
		cocos2d::Vector<cocos2d::SpriteFrame*> animationFrames;
		cocos2d::Vector<cocos2d::SpriteFrame*> animationFramesII;
		cocos2d::Vec2 mArray[20];//CHILD CLASSES COULD USE LESS - BUT ENOUGH GIVEN FOR ALL 
};

#endif

CLASS B BELOW

//OBJECT B - INHERITS A
    #ifndef GAME_OBJECT_PHYSICS_H
    #define GAME_OBJECT_PHYSICS_H

    #include "cocos2d.h"
    #include "GameObject.h"

    class GameObjectPhysics : public GameObject
    {
    	public:

    		virtual cocos2d::PhysicsBody* getPhysicsBody() = 0;

    	protected:

    		GameObjectPhysics(){};
    		virtual ~GameObjectPhysics(){};
    		cocos2d::PhysicsBody* physicsBody;
    };

    #endif

CLASS C BELOW

//OBJECT C - INHERITS B
#ifndef CIRCLE_H
#define CIRCLE_H

#include "cocos2d.h"
#include "GameObjectPhysics.h"

class Circle : public GameObjectPhysics
{
	public:
		Circle();
		~Circle();
		cocos2d::Sprite* getSprite();
		cocos2d::PhysicsBody* getPhysicsBody();
		void animate();
};

#endif

:slight_smile:

IM Rebuilding by last time I tried C didnt have access to “sprite” from A. Maybe it will work now and I have made a mistake posting :frowning:

OK WORKS FINE :frowning:

No idea what was issue before, I literally gave up. Knowing from experience I simple missed something small and completely silly

Thanks anyways dude for help