Quote:This code gave me a couple of errors. I'd love to correct them but I cannot understand what
: Turn(1)
and
, Win(1)
do. If you can explain them to me I can go ahead and get rid of the errors and continue with the more "optimized" classes declaration.
The Win(1) should be Win(0), was too quick on typing.
What this does is same as the following:
class Gomoku{public: Gomoku() { Turn = 1; Win = 0; InitializeGrid(); ShowGrid(); }
Which is the constructor. It'll be called whenever such object is constructed. As pointed out above, it initializes the variables.
This form:
class Gomoku{public: Gomoku() : Turn(1) , Win(0) { InitializeGrid(); ShowGrid(); }
is the preferred syntax using initialization list.
Also, the fact that it's written inside the class definition has no special meaning here, it was just for compact form. You could write it like this:
class Gomoku{public:... Gomoku();...};Gomoku::Gomoku() : Turn(1) , Win(0){ InitializeGrid(); ShowGrid();}
Quote:EDIT: Looking in the actual code I see someone added:
int Turn = 1;
int Win = 0;
Yes, copy paste error. Should be
int Turn;int Win;