Hello programmers!

I am making a player vs. computer Tic-Tac-Toe game in xCode that is a class, with its run() method as its only public member function apart from the initializer. I want to decide whether the player goes first, and I created a function to do that called determineFirst(). This function depends on another one called askYesNoQuestion(const std::string& question) to actually question the player as to him/her going first. My code is below:

bool determineFirst()
{
    //ask player if he wants to play
    static const string question="Do you want to play a game of Tic-Tac-Toe?";
    return askYesNoQuestion(question);
}



bool askYesNoQuestion(const std::string& question)
{
    static char ans;

    //ask question
    std::cout << question << " (yes/no): ";
    std::cin.get(ans);
    std::cout << std::endl;

    //check if the answer is satisfactory (first letter of response only)
    if((toupper(ans)!='N')||(toupper(ans)!='Y'))
    {
        std::cout << "That is not a valid answer to the question"<< std::endl;
        bool yes=askYesNoQuestion(question);
        return yes;
    }
    else
    {
        return toupper(ans)=='Y';
    }
}

However, my xCode editor states that there is "No matching function for call to 'askYesNoQuestion'". This message is showing up on the return statement of determineFirst(). What seems to be the problem

Recommended Answers

All 4 Replies

Did you prototype the functin askYesNoQuestion() at the beginning of your program so that the compiler knows about it?

line 20: It would be better to just set another variable to be toupper(ans) so that toupper() isn't called every time it is used.

I included it in a class header folder, which was added into the class's cpp file.

Are you saying those two functions are members of a c++ class? If yes, then you need to add class decoration to them, for example if the class name is MyClass then line 1 of the code you posted would be

bool MyClass::determineFirst()

and line 20

bool MyClass::askYesNoQuestion(const std::string& question)

Thanks so much!! Such a simple error, and it messed the whole thing up!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.