I'm brand new to C++ (my usual language is Python).
I found out from here how to print an array. I found out from here how to get a class object to cout
as one of its properties. And I found out from here that the cout
only works if it can access the class's property as a friend
.
But, when I combine the answers, it doesn't seem to work. Here's what I've got:
#include <iostream>
using namespace std;
class TicTacToeGame {
int board[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
friend std::ostream &operator<<(std::ostream &os, TicTacToeGame const &m);
};
std::ostream &operator<<(std::ostream &os, TicTacToeGame const &m) {
for (int i = 0; i++; i < 9) {
os << m.board[i];
}
return os;
}
int main()
{
TicTacToeGame game;
cout << game;
return 0;
}
And nothing prints on the screen.
What I'd like to see is something along the lines of {0, 0, 0, 0, 0, 0, 0, 0, 0}
, but fancy formatting isn't needed as long as I can see the array.
How can I get that to happen?