I’m working on my serious c++ program. It’s been awhile since I’ve taken any classes, so I’m a little rusty. When starting the basic implementation of a game loop (After spending freaking FOREVER getting SFML to work), I continually ran into issues. After awhile, I’ve gotten my list of issues down to an error when trying to define a constructor function. I get the following error when trying to compile.
1>game.obj : error LNK2005: “public: __thiscall game::game(void)”
(??0game@@QAE@XZ) already defined in main.obj1>game.obj : error LNK2005: “public: void __thiscall
game::gameLoop(void)” (?gameLoop@game@@QAEXXZ) already defined in
main.obj
My code in main is
#include <SFML/Graphics.hpp>
#include "game.cpp"
int main()
{
return 0;
}
in game.h it’s
#ifndef _game_h
#define _game_h
class game
{
public:
game();
void gameLoop();
};
#endif
and in game.cpp it’s
#include <iostream>
#include "game.h"
game::game()
{
std::cout << "Constructed thingie";
}
void game::gameLoop()
{
std::cout << "RAN LOOP!" << std::endl;
}
I don’t know why I’m running into this error. Any help would be nice as I’d like to get started on my project.
You should include
#include "game.h"in main, notgame.cpp.