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

Author Topic: Inherit from sf::String  (Read 2276 times)

0 Members and 1 Guest are viewing this topic.

Samyboy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Inherit from sf::String
« 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.

Code: [Select]
#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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Inherit from sf::String
« Reply #1 on: May 25, 2010, 12:41:02 pm »
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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Samyboy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Inherit from sf::String
« Reply #2 on: May 25, 2010, 12:57:40 pm »
Quote from: "Nexus"
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!

 

anything