I'm trying to compile the following code in C++
string initialDecision ()
{
char decisionReviewUpdate;
cout << "Welcome. Type R to review, then press enter." << endl;
cin >> decisionReviewUpdate;
// Processing code
}
int main()
{
string initialDecision;
initialDecision=initialDecision();
//ERROR OCCURS HERE
// More processing code
return 0;
}
Right where it says "Error occurs here", I get the following error while compiling: "Error: No Match for Call to '(std::string) ()'. How can I resolve this?
Don't give your string and your function the same name, and the error will go away.
The compiler has "forgotten" that there is a function with that name, when you declare a local variable with the same name.
The local variable shadows the name of the global function. It is best to rename the local variable, but there is also the scope operator which lets you specifically access the global name:
initialDecision = ::initialDecision();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With