SFML community forums

Help => General => Topic started by: BMCha on May 10, 2009, 05:25:56 am

Title: Inheritance Problem?
Post by: BMCha 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 ===|
Title: Inheritance Problem?
Post by: Astrof 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