编译器给出有关对函数的未定义引用的错误

Compiler gives error about undefined reference to a function

本文关键字:未定义 引用 错误 函数 编译器      更新时间:2023-10-16

以下是我的代码编译器说未定义的函数引用。 请详细说明该怎么做。为什么它会给出一个关于布尔函数 isPalindrome((未定义引用的错误?

int main()
{    
        cout << "Please enter a string: ";
        cin >> input;
        cout<<"Vowel Count"<<vowelcount(input);
        while(1)
        {
                if(isPalindrome())
                {
                        palindrome_count++;
                }
        }
        cout<<"palindrome_count"<<palindrome_count;
}
bool isPalindrome(string input)
{
        do{
                if (input == string(input.rbegin(), input.rend())) {
                        cout << input << " is a palindromen";
                }
        }
        while(1);
}

错误消息准确地告诉您需要知道的内容。IsPalindrome 在使用之前不会在代码中定义。 确保在引用它的位置(即在 main 上方(或对函数进行原型设计。

我想,你忘记了函数声明。因此,将 forword 声明放在函数main()上方。喜欢:

bool isPalindrome(string input);