Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Inheritance Problem?  (Read 1817 times)

0 Members and 1 Guest are viewing this topic.

BMCha

  • Newbie
  • *
  • Posts: 3
    • View Profile
Inheritance Problem?
« on: May 10, 2009, 05:25:56 am »
I have a class that inherits from sf::Sprite called AnimSprite.
Now, I'm trying to make a player class that inherits from AnimSprite.
Everything works fine until I try to add a constructor to PlayerClass. Right now the constructor is exactly the same as the (working) AnimSprite constructor.

Code: [Select]

PlayerClass::PlayerClass(std::string ImagePath) {
    if (!MyImage.LoadFromFile(ImagePath)) throw(-1);
    SetImage(MyImage);
}


This is the Error
Code: [Select]

In constructor `PlayerClass::PlayerClass(std::string)':
error: no matching function for call to `AnimSprite::AnimSprite()'
note: candidates are: AnimSprite::AnimSprite(const AnimSprite&)
note:                 AnimSprite::AnimSprite(std::string)
|=== Build finished: 1 errors, 0 warnings ===|

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Inheritance Problem?
« Reply #1 on: May 10, 2009, 06:34:19 am »
it probably means you do not have a default constructor.  You need to call your AnimSprite constructor that takes an argument with an initialization list (use the : ).

Check out: http://www.cprogramming.com/tutorial/initialization-lists-c++.html