1
resposta

problemas com abs. "abs is ambiguous"

Quando passo o mouse por cima do abs a mensagem que aparece é "abs is ambigous" e eu nao sei como consertar. `#include //input-output library using namespace std;

int main () { cout << "****" << endl; //cout will print & endl will jump to the next line cout << "* Welcome to the Guessing Game " << endl; cout << "***" << endl;

const int SECRET_NUMBER = 42;

bool incorrect_guess = true;
int attempts = 0;

double points = 1000.0;

while(incorrect_guess){
    attempts ++;
    int guess;
    cout << "Attempts: " << attempts << endl;
    cout << "What is your guess?" << endl;
    cin >> guess; //guess input

    double lost_points = abs(guess - SECRET_NUMBER) / 2.0;
    points -= lost_points;

    cout << "You guessed: " << guess << endl;

    bool guessed = guess == SECRET_NUMBER;
    bool bigger = guess > SECRET_NUMBER;

    if(guessed){
        cout << "Congratulations! You've guessed the secret number!" << endl;
        incorrect_guess = false;
    }
    else if(bigger){
        cout << "The number you guessed was bigger than the secret number!" << endl;
    }
    else{
        cout << "The number you guessed was smaller than the secret number!" << endl;
    }
}
cout << "Game Over!" << endl;
cout << "You guessed after " << attempts << " attempts!" << endl;
cout.precision(2);
cout << fixed;
cout << "Score: " << points << endl;

}`

1 resposta

Geralmente, em C++ é recomendado não usar using namespace std, seria melhor indicar using std::function ou então no próprio código trocar todas as funções do std por std::function. Provavelmente alguma biblioteca que você está usando já tem outra declaração da função abs, e está confundindo o compilador, evitando chamar using namespace std deve o problema.

Fonte: https://stackoverflow.com/questions/29387600/reference-to-is-ambiguous