1

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.

4

2 回答 2

8

Missing ; at the end of class definition.

class GameWindow
{
   // .....

}; // Missing semi-colon
于 2013-09-06T12:44:56.070 回答
0

失踪 ; 在类定义 { };

因此,当您在程序中包含文件时,编译器找不到类的结尾,因此它说 main 的返回类型应该是 int 而不是 GameWindow

于 2013-09-06T13:21:53.573 回答