I am trying to make the game tic tac toe. I am suppose to have two classes one called board where the board is created and the moves are made. The other class is called TicTacToe where it loops and checks to see who won.
I am trying to figure out how to print the game board with in my play function in TicTacToe class.
From what I understand, your Board::print(); is proper, but certain IDEs and compilers only interpret certain ways of calling functions within classes. If you are using Visual Studio, my understanding is that VS only recognizes Board->print();. As far as telling the IDE that the certain function is part of the class, '::' is proper. You're good there.
Secondly, you're coding in a function "play()" outside of the TicTacToe class that's already created inside the TicTacToe class. Why don't you just code it within that function? It's a little redundant, isn't it?
Well there's a couple of thing I'd like to comment on.
Firstly, the design is not something to be admired. But besides that:
1) In your class Board, there is a closing curly bracket missing '}'. Fix that first. :)
2) Board::print() This is a call to a static function. If you really mustn't create an object and call the function through the object, then you'd better declare print() to be static!
3) In the main function you call TicTacToe::print(). Now this would never work, unless TicTacToe derives from Board and print() is a staticfunction. I think you meant to call TicTacTo::play(). That too would be a staticfunction call, so you should know what to do.
Thank you so much WakeofMisery and sasauke! I was able to get it working
Side note the reason why I called the function "play()" out side the class is because the homework calls for an hpp and a cpp file.
In the main function, you create an object of TicTacToe game and you call play() from that object. In this case there is no need for play() to be static. A staticmember function is only used whenever you want to call it without an associated object of the class, as is the case with Board::print().