Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Need help on a Design problem with a class

This topic is 5574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include <string>
using std::string;

struct ScoreInfo
    string name;
    int score;

class Highscore
    ScoreInfo[10] scores;
    string path;

    HighScore(string filename);

    void Draw();
    int EnterScore(ScoreInfo score);
Right now ScoreInfo is hardcoded into the class. I want to be able to use different types of ScoreInfo''s without having to rewrite a lot of code, I was thinking of making Draw and EnterScore virtual and in a base class define those methods. But a friend said just make the methods templated and the private Variable scores a templated arguement. I can''t really see the best design I should go with.

Share this post

Link to post
Share on other sites
So, what are you trying to accomplish? Have different scores like HighScore, LowScore, AverageScore, etc.?

The question you should ask yourself when deciding between templates and polymorphism is if you''ll need runtime-typing (i.e. do you need to be able to have functionality that doesn''t know or doesn''t care what type of score it''s using) or static-typing (you''ll know what type of score you''re working with in your app at all times at compile time). If it''s the former, you need inheritance and polymorphism. If it''s the latter, you can use templates.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!