SFML community forums
Help => Graphics => Topic started by: Samyboy on May 25, 2010, 11:58:37 am
-
Hello,
Is it possible to inherit from sf::String? I am currently trying to write a Score class to make my life easier, but it doesn't quite work.
Here is how I inherit from sf::String, the constructor of sf::String gets called in my constructor, btw.
#ifndef SCORE_H_INCLUDED
#define SCORE_H_INCLUDED
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
namespace readOnly {
class Score : public sf::String {
public:
Score(float PosX = 0, float PosY = 0);
~Score();
void SetScore(int score);
void Add(int addScore = 1);
const int& GetScore() const;
void Update();
private:
int m_score;
};
}
#endif // SCORE_H_INCLUDED
-
It is possible, but not meaningful in your situation. You should prefer containment/aggregation to inheritance where possible. How is your class related to sf::String?
By the way, you shouldn't implement the destructor unless the copy constructor and assignment operator are implemented, too, or hidden (Rule of the Big Three). If the destructor is empty, just don't declare it.
-
It is possible, but not meaningful in your situation. You should prefer containment/aggregation to inheritance where possible. How is your class related to sf::String?
By the way, you shouldn't implement the destructor unless the copy constructor and assignment operator are implemented, too, or hidden (Rule of the Big Three). If the destructor is empty, just don't declare it.
Hello,
Thank you very much for your input!