Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

[SOLVED] 'Game' does not compile.

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 Dennisvb   Members   

160
Like
0Likes
Like

Posted 03 March 2013 - 06:21 AM

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?



#2 stevo5800   Members   

182
Like
3Likes
Like

Posted 03 March 2013 - 07:12 AM

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();

}


Edited by stevo5800, 03 March 2013 - 07:21 AM.


#3 Banderi   Members   

192
Like
0Likes
Like

Posted 03 March 2013 - 07:46 AM

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



#4 Dennisvb   Members   

160
Like
0Likes
Like

Posted 03 March 2013 - 08:40 AM

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






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.