Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Error: No Match for Call

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?

like image 452
waiwai933 Avatar asked Oct 10 '09 18:10

waiwai933


2 Answers

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.

like image 165
Mark Rushakoff Avatar answered Sep 23 '22 13:09

Mark Rushakoff


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();
like image 22
UncleBens Avatar answered Sep 20 '22 13:09

UncleBens