C++ Error: No Match for Call

waiwai933 picture waiwai933 · Oct 10, 2009 · Viewed 38.9k times · Source

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?

Answer

Mark Rushakoff picture Mark Rushakoff · Oct 10, 2009

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.