kingblade
kingblade

Reputation: 113

C++ help writing a class with declaration on header file

Well, hi there.

I'm new to c++ and I'm having some issues that I'm not sure what is causing them. This is my main:

#include "GameWindow.h"

int main(void)
{
    GameWindow * game_window = new GameWindow(true);

    /* loop the game */
    while (game_window->GetRunning())
    {
    // update
    game_window->Update();

    // draw
        game_window->Draw();
    }

    delete game_window;
    return 0;
}

and this is my header:

class GameWindow
{
private:
    bool _running;
    //GLFWwindow* _window;

public:

    void SetRunning(bool new_val);
    bool GetRunning();


    GameWindow(bool running);

    void Draw();
    void Update();
}

and my c++ file:

#include "GameWindow.h"

void GameWindow::SetRunning(bool new_val)
{
    _running = new_val;
}

bool GameWindow::GetRunning()
{
    return _running;
}

GameWindow::GameWindow(bool running) :
    _running(running)
{

}

void GameWindow::Draw()
{

}

void GameWindow::Update()
{

}

While going through all of this I find it tough to find why Visual Studio refuse to compile this code. It's raising errors about how 'SetRunning' is overloading a function which differs only in return values, and that the return type of main should be Int and not GameWindow, and with all of this I just went completely lost. Tried to put 'SetRunning' as a comment to simplify the issue but instead it raised the same on 'GetRunning' instead. I'm guessing it's a really stupid mistake that is easy to fix, but still, can't find it.

Thank you for your time, and I'll appreciate any kind of help.

Upvotes: 1

Views: 960

Answers (2)

Santosh Belavi
Santosh Belavi

Reputation: 1

Missing ; in class defination { };

because of this when you include the file in program then compiler not found the end of the class hence it says return type of main should be int not GameWindow

Upvotes: 0

Mahesh
Mahesh

Reputation: 34625

Missing ; at the end of class definition.

class GameWindow
{
   // .....

}; // Missing semi-colon

Upvotes: 8

Related Questions