When trying to access a member function in C without using the function call syntax, Visual Studio 2015 encounters an error: "non-standard syntax; use '&' to create a pointer to member."
In Visual Studio, non-member functions can be used in expressions without using the function call syntax. However, for member functions, this is not allowed. To obtain a pointer to a member function, it is necessary to use the '&' operator.
The solution to the error is to prefix the problematic member function name with the '&' operator, creating a pointer to the member function. By doing this, the function can be used in expressions without the function call syntax.
Consider the following class definition:
<code class="cpp">class TicTacToe { public: void player1Move(string coordX); };</code>
To access the player1Move member function without using the function call syntax, use the following pointer to member:
<code class="cpp">TicTacToe::&player1Move;</code>
This pointer to member can now be used in expressions without calling the function explicitly:
<code class="cpp">TicTacToe Board; (Board.*player1Move)("some_coordinate");</code>
By using the '&' operator, Visual Studio can correctly interpret the intent and avoid the non-standard syntax error.
The above is the detailed content of Why Does Visual Studio 2015 Require \'&\' to Create a Pointer to a Member Function?. For more information, please follow other related articles on the PHP Chinese website!