Tic Tac Toe Problem with Class Function

So I'm working on setting up this Tic Tac Toe program

Main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include "tictactoe.h"

using namespace std;

int main()
{
    ticTacToe TTT;

    TTT.setBoard();

    return 0;
}


tictactoe.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include "tictactoe.h"

using namespace std;

void ticTacToe::setBoard()
{
    char board[3][3] =
    {
	  {'1','2','3'},
	  {'4','5','6'},
	  {'7','8','9'},
	};

	for(int row = 0; row < 3; row++)
	{
		for(int column = 0; column < 3; column++)
		{
			cout << board[row][column] << " ";
		}
		cout << endl;
	}
}


tictactoe.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef TICTACTOE_H
#define TICTACTOE_H

class ticTacToe
{
    private:
        char board[][3];
    public:
        void setBoard();
    protected:

};

#endif // TICTACTOE_H 


I was attempting to set the values 1-9 for the two dimensional array board (has to be two dimensional 3x3 array) and then cout so I could make sure that everything was in there properly. However, every time I try to compile this I receive

|10|undefined reference to `ticTacToe::setBoard()'|

But right there in the .cpp I stated specifically that setBoard() was part of ticTacToe, so I'm not really sure why it is kicking that back. Help please? This project is due tomorrow at midnight (accelerated course) so I'd appreciate any help you guys can offer!
Last edited on
Have you try to put void ticTacToe::setBoard(); before the main() ?
Yeah, I just gave that a shot but it doesn't seem to do anything but make its own errors. Someone in another site was talking about how do I link my program together but to be honest I'm pretty confused, I thought the whole point of the #include's was it add them to other files...
closed account (SECMoG1T)
Well undefinef ref myabe on yah includes whatever am not sure coz it works well on my compiler but am gonna point out some bugs av seen

1
2
in function setboard
char board[3][3] = { 	 {'1','2','3'}, 	 {'4','5','6'}, 	 {'7','8','9'}, 	}; 


The above code does nothing to you class member board
What it does is create a local variable similar your class board member and intialize it with
The list in braces , if you could call setboard successfuly after that call is over this variable would be
Destroyed. An alternative is to initialize your member board with a constructor and set the board directly
Or do it iside the class with uniform intialization similar to wat you have done but inside the class , While you could use your setboard function only to print the board or change the board values.

If you included iostream in your ttt.cpp it won't be necessary to reinclude it in main since you are including the ttt.h in main.
Last edited on
Topic archived. No new replies allowed.