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

  • SEARCH
  • Home
  • 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 3314176
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:12:03+00:00 2026-05-17T22:12:03+00:00

I have a Player class that derives from Humanoid and Humanoid derives from Sprite

  • 0

I have a Player class that derives from Humanoid and Humanoid derives from Sprite like so

Sprite -> Humanoid -> Player

So far so good. Sprite has the virtual method

virtual sf::Sprite getSprite() { return sprite_; }

where sprite is an image object that can be drawn onto the screen.

Humanoid declares virtual sf::Sprite getSprite();

Player defines virtual sf::Sprite getSprite() { return sprite_; }

Sprite has a member sprite_; this is what I want to do:

1) Create a player class while passing a sprite like so

Player::Player(sf::Image image)
    : Humanoid()
{   
    sprite_.SetImage(image); // Converts sf::Image to sf::Sprite
}

2) Drawing it on the screen from my Game class like so

sf::Image playerImage;
if(!playerImage.LoadFromFile("Link/Link.png"))
    std::cin.get();

Player *player = new Player(playerImage);

/* ... */

App.Draw(player->GetSprite());

Testing the program, I have found that the player->getSprite() method is indeed called, but I fear that I may have hidden the Sprite::getSprite() method instead of actually deriving and using it. Since the Sprite class has a protected sprite_ member, I’m confused as to which sprite_ object I’m actually returning when I call the function.

Also, it seems like the image file got lost somewhere along the line, and before I post in the SFML forum I would like some confirmation as to whether or not my inheritance tree is actually correct or not.

  • 1 1 Answer
  • 1 View
  • 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-05-17T22:12:04+00:00Added an answer on May 17, 2026 at 10:12 pm

    If the Sprite class has a sprite_ member and none of the derived classes (Humanoid/Player) have added a member with the same name then there is only one sprite_ object for each instance and the function should work as expected. I don’t understand why you’re overriding getSprite if you give it the exact same behaviour though.

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

Sidebar

Related Questions

Say as an example I have a Player class that has a race via
I have a class Player that contains a list of Accessory objects. There are
I have a Club class and a Player Class. The player class has an
I have a class that contains player numbers... public class Game { public int
I have a class player and player has a list of Shots. Each shot
Alright lets say I have a cPlayer class that inherits from cOrganism , which
I have a Player class that uses a ForeignKey to a Photo object for
I have a class Player which I load from a database: public class Player{
I have a Player class that extends CCNode, and i want to hava a
I have a class Player that is a subclass of UIImageView. They are spawned

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.