I am getting a couple of errors when I compile this program and all I seem to be doing today is making them worse.
This program is a homework program that I did before and it worked, but my program structure was totally different. I am re-writing it again as a class(we are working about classes , structs, inheiritance etc., and I wanted to try out this new material on a program that I had done before), but have screwed up in my functions and am just confused now. I know this is a case of messing with it for too long and the more I try to correct it the more I am messing it up.
Specifically, I am getting error code C2601 on line string reverse(string word) and bool pal(string word).Code:#include <string> #include <iostream> using namespace std; class PString : public std::string { public: PString( const std::string &aString ); bool isPalindrome() const; }; PString::PString( const std::string &aString ) : std::string( aString ) { } bool PString::isPalindrome() const { string reverse(string word) { string reverse; int length=word.length(); for(int i=length;i>=0;i--) { reverse=reverse+word[i]; } return reverse; } bool pal(string word) { bool pal=true; if(word!=reverse(word)) { pal=false; } return pal; } return true; } int main() { std::string str; std::cout << "This program is a palindrome-testing program. Enter a string to test:\n"; std::cin >> str; // Create a PString object that will check strings PString s(str); // Check string and print output if (s.isPalindrome()) { std::cout << s << " is a palindrome"; } else { std::cout << s << " is not a palindrome"; } std::cout << std::endl; system("pause"); return 0; }
I get error C2780 two lines below that line and it tells me there is a problem in the void function- but I have no void function.
What do I need to look at to get this to work? (Besides aspirin and a stiff drink!)