Hi, I'm trying to create a snake game. For that I created some classes (Coordinates, Snake and Board).The classes and their data fields are something like:
//main.cpp
#include "Board.h"
int main()
//Board.h
#include "Snake.h"
class Board {
Snake snake;
Coordinates food;
std::deque< std::deque<char> > cells;
};
//Snake.h
#include <deque>
#include "Coordinates.h"
class Snake {
std::deque<Coordinates> body;
};
//class Coordinates only has 2 ints, so nothing #included
I tried to follow http://www.cplusplus.com/forum/articles/10627/ so each .cpp #includes its own header and nothing more and each .h is "guarded" with #ifndef, #define and #endif. Even though I did all that, I'm still getting some linker errors. Can anyone help me doing the right #includes?
[EDIT] I also have other #includes, could that be the problem?
The others are:
iostream
conio.h
cstdlib
time.h
I'm sorry I wasn't clear. What I wrote above isn't the actual whole code, just the really important things. So I actually have the main() defined.
Since the compiler reports linker errors, I assume the cause is somewhere in the #includes. I even though it was because I #included every header file twice (Board.h in Main.cpp and Board.cpp; Snake.h in Board.h and Snake.cpp; Coordinates.h in Snake.h and Coordinates.cpp). But there's no way around that, I think.
[EDIT] The errors are the following:
error LNK2019: unresolved external symbol "public: __thiscall Coordinates::Coordinates(void)" (??0Coordinates@@QAE@XZ) referenced in function "public: __thiscall Board::Board(class Board const &)" (??0Board@@QAE@ABV0@@Z) C:\...\visual studio 2013\Projects\Snake\Snake\Board.obj
error LNK2019: unresolved external symbol "public: __thiscall Snake::Snake(void)" (??0Snake@@QAE@XZ) referenced in function "public: __thiscall Board::Board(class Board const &)" (??0Board@@QAE@ABV0@@Z) C:\...\visual studio 2013\Projects\Snake\Snake\Board.obj
error LNK2019: unresolved external symbol "public: __thiscall Board::Board(void)" (??0Board@@QAE@XZ) referenced in function _main C:\...\visual studio 2013\Projects\Snake\Snake\Source.obj
error LNK1120: 3 unresolved externals C:\...\visual studio 2013\Projects\Snake\Debug\Snake.exe
Now that I think about it, I only declared the default constructors, didn't implement them. Is that it?