When writing code in C , programmers often encounter errors like "non-standard syntax." This error occurs when an operation is performed using syntax that is not officially recognized by the C language.
In your specific case, the error originates from the following code:
<code class="cpp">void TicTacToe::player1Move(string coordX) // ERROR { cout << "Enter X: " << endl; cin >> coordX; _coordX = coordX; }</code>
Here, the player1Move function is a member function of the TicTacToe class. However, the function name is used as a single expression, without invoking the function call syntax. According to C conventions, this is incorrect for member functions.
To correctly obtain a pointer to a member function, you need to use the address-of operator (&). This operator creates a reference to the function memory location, enabling us to access the function indirectly.
The fix to your code is:
<code class="cpp">void TicTacToe::player1Move(string coordX) { cout << "Enter X: " << endl; cin >> coordX; _coordX = coordX; }</code>
With this change, the player1Move function can be invoked correctly by other parts of the program using the . operator, like this:
<code class="cpp">TicTacToe Board; Board.player1Move("1");</code>
The above is the detailed content of Why Am I Getting a \'Non-standard Syntax\' Error in My C Code?. For more information, please follow other related articles on the PHP Chinese website!