[SOLVED] 'Game' does not compile.

Started by
2 comments, last by Dennisvb 11 years, 1 month ago

Hello,

I have my main.cpp:


#include "Game.h"

int main( int argc, char* args[] )
{
	Game game;
	game.Start();

	return 0;
}

My Game.cpp:


#include "Game.h"

class Game
{
	// Starts the game
	void Game::Start()
	{
		SDL_Init( SDL_INIT_EVERYTHING );

		SDL_Quit();
	}
};

And my Game.h:


#ifndef _GAME_H_
#define _GAME_H_

#include "SDL.h"
#include "SDL_image.h"

class Game
{
public:
	void Game::Start();
};

#endif // _GAME_H_

But when I compile I get this error:


1>------ Build started: Project: Pong Clone, Configuration: Debug Win32 ------
1>  main.cpp
1>  Game.cpp
1>c:\users\dennis\documents\visual studio 2012\projects\pong clone\pong clone\game.cpp(4): error C2011: 'Game' : 'class' type redefinition
1>          c:\users\dennis\documents\visual studio 2012\projects\pong clone\pong clone\game.h(8) : see declaration of 'Game'
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How can I fix this?

Advertisement

you have 2 definition of the class here's what it should look like

header file

class Game

{

// Starts the game

void Start();

};

cpp file

#include "Game.h"


void Game::Start()

{

SDL_Init( SDL_INIT_EVERYTHING );

SDL_Quit();

}

Yeah, as Stevo said, the function "Game::Start();" doesn't need another "Class Game" definition, just have it out of it.

Thank you, that fixed it. Stupid mixtape ;).

This topic is closed to new replies.

Advertisement