Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[SOLVED] 'Game' does not compile.


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   -  Reputation: 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?



Sponsor:

#2 stevo5800   Members   -  Reputation: 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   -  Reputation: 135

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   -  Reputation: 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.



PARTNERS