-1

Following is my code compiler says undefined reference to function . please elaborate what to do. Why does it give an error about undefined reference to the function isPalindrome() which is boolean?

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 palindrome\n";
                }
        }
        while(1);
}
msc
  • 33,420
  • 29
  • 119
  • 214
Muhammad Shahid
  • 81
  • 2
  • 12
  • Please post a complete program next time. You omitted some stuff from before `main()` that is relevant to the problem – M.M May 16 '17 at 09:42

2 Answers2

0

The error message is telling you exactly what you need to know. IsPalindrome isn't defined in your code before you use it. Make sure to define it above where you reference it (i.e above main) or prototype the function.

forsamori
  • 21
  • 7
0

I think, you have forgot function declaration. So, put the forword declaration above main() function. Like:

bool isPalindrome(string input);
msc
  • 33,420
  • 29
  • 119
  • 214
  • 1
    exactly I forgot about passing the argument input to the function . I solved it thanks a lot. – Muhammad Shahid May 16 '17 at 08:43
  • You're recommending the op invoke ub? O_o – George May 16 '17 at 08:57
  • You are mistaking errors. If the function were not declared - you would get _compiler_ error about _unknown identifier_, not a _linker_ error. This error suggests that function was declared, but not defined. If you look at the signature of function definition (`bool isPalindrome(string input)`), and how it's called (`isPalindrome()`) - you would notice that they are mismatched, which, most likely, is the cause of the error. – Algirdas Preidžius May 16 '17 at 09:13