I have to create a program that uses a class Pstring derived from the STL class. The only error I am getting says that I have one unresolved external. How do I fix this? Here is my code:

#include <string>

class Pstring : public std::string
{
public:
    Pstring(const std::string &text)
        : std::string(text) { }

    bool isPalindrome()
    {
        std::string::size_type len = length();
        std::string::size_type half = len / 2;
        for (std::string::size_type idx = 0; idx < half; ++idx)
        {
            if ((*this)[idx] != (*this)[len-idx-1])
                return false;
        }
        return true;
    }
};
Re: How do I fix this simple C++ program? (Only one error message) 80 80

I don't get any errors with that code using VC++ 2012. The error is probably somewhere else.

Re: How do I fix this simple C++ program? (Only one error message) 80 80

Odd that your prof is asking you to derive from a base STL class.

All the literature on the net suggests it's a no no. I'm sure there are better learning merits from deriving your OWN class as the syntax looks a little tricky as well.

Be a part of the DaniWeb community

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