Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8379271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:08:03+00:00 2026-06-09T16:08:03+00:00

I’m writing a simple game in SDL. I have a class heirarchy that I

  • 0

I’m writing a simple game in SDL. I have a class heirarchy that I am constructing for any sprite I use in the game. The base class is Sprite, which contains data abstractions for the collision box and the spritesheet. Directly below that are two abstract classes, Character and MapObject.

I am currently implementing the Player class which is derived from Character (Enemy and NPC will also be derived from the abstract Character class).

Anyway, hopefully that makes sense. My problem is this:

When I try and use the player class in the engine, I cannot access any of the Sprite functions.

I get the following error:

'Sprite' is not an accessible base of 'Player'

Here are the header files:

Sprite.h:

class Sprite{
public:
    virtual ~Sprite() = 0;  //I want this to be an abstract class and yes this is defined in the cpp

    //Initialization functions - MUST be called before anything else in the class can be used.
    void setupCollider(int xo, int yo, int ho, int wo);
    void setupSheet(SDL_Surface* dest, std::string file, int numClips, int ac, int _res, int sr);

    //SpriteSheet functions
    void setActiveClip(int a);
    int getActiveClip() const;
    void draw() const;
    int getResolution() const;
    SDL_Surface* getDest();


    //Collider functions
    void updateCollider();
    SDL_Rect box() const;
    bool collision(SDL_Rect other) const;

    //Access and Modify coordinates of the sprite
    void setLoc(int x, int y) { _x = x; _y = y; }
    int getX() const { return _x; }
    int getY() const { return _y; }

private:
    struct Collider{
        SDL_Rect  _box;
        int       x_offset,
                  y_offset;
    };

    struct SpriteSheet{
        SDL_Surface*     destination;
        SDL_Surface*    sheet;
        SDL_Rect*       clips;
        int             _numClips;
        int             active;
        int             res;
        int             sheetrows;
    };


    Collider     collisionAttributes;
    SpriteSheet  spriteSheetAttributes;
    int          _x, _y;

};

Character.h:

class Character : public Sprite{
public:
    virtual void move(Direction direction_input, const TileMap& currentlevel) = 0;
    virtual void animate() = 0;

    virtual void setAttributes( int h, int sp, int ad, int d, int m, int md, int l, std::string n){
        hearts = h; speed = sp; attackdamage = ad;
        defense = d; magicdamage = m; magicdefense = md;
        level = l; name = n;
    }

    bool isDead() const{
        return hearts == 0;
    }

    void heal(int heartsup){
        hearts += heartsup;
    }

    void dealDamage(int heartsDown){
        hearts -= heartsDown;
    }


protected:

    int hearts;
    int speed;
    int attackdamage;
    int defense;
    int magicdamage;
    int magicdefense;
    int level;
    std::string name;

};

Player.h:

//Not fully finished yet, but should work for the purposes of this question
class Player : protected Character{
public:
    ~Player(){
        if(heart) SDL_FreeSurface(heart);
    }
    static const int HEART_WIDTH;

    void move(Direction direction_input, const TileMap& currentlevel);
    void animate();

    void updateCamera(TileMap& currLevel);


 private:

    SDL_Surface* heart;

    enum ClipFace
    {
        UP1,
        UP2,
        DOWN1,
        DOWN2,
        LEFT1,
        LEFT2,
        RIGHT1,
        RIGHT2
    };

    static const std::string HEART;
    static const int HEART_RES;

};

I get the first error in my engine when I try to call the setup functions from Sprite in player, the first one being:

player.setLoc(levels[0].startX(), levels[0].startY());

Any and all help is appreciated.

[SOLVED] EDIT: An alternative solution to the comments: The character class didn’t inherit anything from the Sprite class, so it didn’t technically have to be derived from it. Instead of having Character inherit from Sprite, I had Player inherit from BOTH Sprite and Character and that also worked. I’m not sure what is better design though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:08:05+00:00Added an answer on June 9, 2026 at 4:08 pm

    I think you need to change

    class Player : protected Character{
    

    to

    class Player : public Character{
    

    That way you can access Character and Sprite‘s functions on a Player object from an instance of Player created anywhere in your program.

    If a Player should be able to do anything a Character can do, public inheritance makes sense. There’s no reason to hide something in Player that would be freely accessible in Character or Sprite objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.