Why am I getting this redefinition error?

Why am I getting this redefinition error?

console output:

$ g++ -c main.cpp Game.cpp -lSDL2
Game.cpp:4:6: error: redefinition of ‘bool Game::init(const char*, int, int, int, int, int)’
bool Game::init(const char* title, int xpos, int ypos, int width,
^~~~
In file included from Game.cpp:1:0:
Game.h:14:7: note: ‘bool Game::init(const char*, int, int, int, int, int)’ previously defined here
bool init(const char* title, int xpos, int ypos, int width,
^~~~


main.cpp - https://pastebin.com/bDShVR2z
Game.cpp - https://pastebin.com/m9011azc
Game.h - https://pastebin.com/j0WckxQT
You have (effectively) in the Game.h:
1
2
3
4
5
bool Game::init( const char* title, int xpos, int ypos,
                 int width, int height, int flags)
{
  m_bRunning = true;
}


and in the Game.cpp:
1
2
3
4
5
6
7
#include "Game.h"
 
bool Game::init( const char* title, int xpos, int ypos,
                 int width, int height, int flags)
{
  // lots 
}

Two implementations for the Game::init() function.
How am I supposed to code it correctly? I just followed what it said in my book?
You're defining init() in your header to do different behavior than what you do in your .cpp file (as keskiverto pointed out).

Since it looks like the definition within your header file is a remnant of the past, remove it and just leave the declaration:
bool init( const char* title, int xpos, int ypos, int width, int height, int flags);
Last edited on
Thanks for your help i got a successful compilation
Topic archived. No new replies allowed.