Preprocessor Directives

Hello all. I am wrapping up a tictactoe program and have run across a problem. I divided my program into three files.. the main .cpp file, a tictactoe class .h file, and a tictactoe class .cpp file.
I am not sure how to set up my preprocessor directives which I believe is causing errors. Here are my directives per file:

Source1.cpp file -
1
2
3
4
#include <iostream>
#include "gameBoard.h"

using namespace std;


gameBoard.h file -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <string>
#include <vector>

using namespace std;

class gameBoard
{
public:
	void printBoard() const;
	void setPlayers();
	void getMove(int player);
	bool isMoveValid() const;
	void setMove(int player);
	bool isWinner() const;
         string getPlayerOne() const;
	string getPlayerTwo() const;
	gameBoard();
	
private:
	char board[9];
	char move;
	vector<char> movesTaken;
	string playerOne;
	string playerTwo;
};


gameBoardImp.cpp (implementation) -
1
2
3
4
5
6
#include <iostream>
#include <string>
#include <vector>
#include "gameBoard.h"

using namespace std;


Here are the errors:
1>------ Build started: Project: TicTacToe, Configuration: Debug Win32 ------
1> Source1.cpp
1>Source1.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall gameBoard::getPlayerTwo(void)const " (?getPlayerTwo@gameBoard@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main
1>Source1.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall gameBoard::getPlayerOne(void)const " (?getPlayerOne@gameBoard@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main
1>Source1.obj : error LNK2019: unresolved external symbol "public: bool __thiscall gameBoard::isWinner(void)const " (?isWinner@gameBoard@@QBE_NXZ) referenced in function _main
1>Source1.obj : error LNK2019: unresolved external symbol "public: void __thiscall gameBoard::setMove(int)" (?setMove@gameBoard@@QAEXH@Z) referenced in function _main
1>Source1.obj : error LNK2019: unresolved external symbol "public: bool __thiscall gameBoard::isMoveValid(void)const " (?isMoveValid@gameBoard@@QBE_NXZ) referenced in function _main
1>Source1.obj : error LNK2019: unresolved external symbol "public: void __thiscall gameBoard::getMove(int)" (?getMove@gameBoard@@QAEXH@Z) referenced in function _main
1>Source1.obj : error LNK2019: unresolved external symbol "public: void __thiscall gameBoard::printBoard(void)const " (?printBoard@gameBoard@@QBEXXZ) referenced in function _main
1>Source1.obj : error LNK2019: unresolved external symbol "public: void __thiscall gameBoard::setPlayers(void)" (?setPlayers@gameBoard@@QAEXXZ) referenced in function _main
1>Source1.obj : error LNK2019: unresolved external symbol "public: __thiscall gameBoard::gameBoard(void)" (??0gameBoard@@QAE@XZ) referenced in function _main
1>C:\Users\Kevin\documents\visual studio 2010\Projects\TicTacToe\Debug\TicTacToe.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
If the header-file is called TicTacToe.h, why are you including "gameBoard.h"? Also, what kind of problem are you having? Is the code not compiling?

EDIT: Ok, looking at your errors now. Have you remembered to put gameBoard:: in front of all the function-implementations?
Last edited on
My .h file is called gameBoard.h. Sorry about that, I will edit the post. I am able to run the program successfully if I do not divide the program into multiple files. In other words, when I place the class definition, int main(), and the class implementation in the same file, it works.
Yes, I did put gameBoard:: in front of the function names.
Last edited on
Hmm, strange. Could you post the .cpp file?

EDIT: Also, depending on how you compile, I guess, maybe you should try use the same name for the .h and .cpp files.
Last edited on
Hey sorry I just found the problem after about 3 hours.
I did not "move" the header and implentations files into my TicTacToe project.
They were in my directory, so I didn't realize that had to be done... if anyone would like to play, PM me and ill send you the file
Last edited on
Allright, good you worked it out:) That same thing happened to me before too:p
put the #include "gameBoard.h" after the using namespace std;. This should fix the problem.
Topic archived. No new replies allowed.