In this exercise, I tried making a string variable “Guess” assigned the output from the function Guess().
string Guess = Guess();
I get this cryptic syntax error:
std::string Guess
call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type
The problem is easily resolved by changing the name of either the variable or the function so they don’t exactly match. This is obviously some kind of naming conflict.
I would like to understand this better, because I know this wouldn’t cause problems in Java code.
- Can anyone help me decipher the error message, or explain what operator() is?
- Why is this a problem? I would have thought variables and functions occupy different namespaces.
- Is there a simple syntax trick in C++ that would allow me to use the same named variable and function, kind of like Java’s “this.” syntax?
Here’s a more complete sampling of the code.
string Guess()
{
// STUFF
return Guess;
}
int main()
{
string Guess = Guess();
return 0;
}
Thanks for any help!