Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cpp : Is there a way to avoid creating header files in this case?

I have an abstract class called Screen :

class Screen {
public:
    virtual void init() = 0;
    virtual void update(float dt) = 0;
    virtual void handleInputs(ScreenManager* screenManager) = 0;
    virtual void dispose() = 0;
};

And every time I want to create a new Screen I have to:
1 : Create a header file :
Ex :

class MenuScreen : public Screen {
public:
    void init() override;
    void update(float dt) override;
    void handleInputs(ScreenManager* screenManager) override;
    void dispose() override;
};

2 : Create a cpp file :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

void MenuScreen::init() {

}

void MenuScreen::update(float dt) {
    
}

void MenuScreen::handleInputs(ScreenManager* screenManager) {
    
}

void MenuScreen::dispose() {

}

Now my problem is I have so many screens , and every time I want to create a new Screen I have to copy and past the header file and all what I have to change is the class name , is there a better way to do that ? am I doing that right ? any help would be appreciated.


>Solution :

You don’t have to put all the code in seperate files. If many screens are related or if they are part of a group, you could put them in a single file. You may also use seperate files only for big classes with a lot of code

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading