Hi everyone, I have a base class "String" and derived the class "ReverseString" from "String". When I try to use member variables from String in the ReverseString class, it is telling me "ReverseString has no member ' ' "
Here is my ReverseString class:
In the .cpp file for my ReverseString class, it is telling me "ReverseString has no member 'length'"Code:class ReverseString : public String{ public: ReverseString() : String(); ReverseString(const ReverseString&) : String(const String&); ReverseString(char*) : String(char*); friend ReverseString operator+(const ReverseString&, const ReverseString&); ReverseString operator~(); };
Edit: Here is my String class in case you need to see it:Code:... ... ReverseString operator+(const ReverseString& strA, const ReverseString& strB){ int len = strA.length + strB.length; int count = 0; char* temp; temp = new char[len]; for(int i = 0; i < strA.length; i++){ temp[i] = strA.buf[i]; count++; } for(int i = 0; i < strB.length; i++){ temp[i+count] = strB.buf[i]; } return temp; } ... ...
length is a protected member variable in my String class, so shouldn't it be automatically included in the ReverseString class?Code:class String{ protected: int length; char* buf; public: String(); String(char*); String(char); String(int); String(const String&); String(char, int); ~String(); String& operator=(const String&); String& operator=(const char*); friend String operator+(const String&, const String&); friend String operator+(const String&, const char*); friend String operator+(const char*, const String&); friend String operator+(const String&, char); friend String operator+(char, String&); String& operator+=(const String&); String operator+() const; friend int operator==(const String&, const String&); friend int operator!=(const String&, const String&); friend int operator<(const String&, const String&); friend int operator<=(const String&, const String&); friend int operator>(const String&, const String&); friend int operator>=(const String&, const String&); char& operator[](int); friend char* operator+(const String&, int); friend char* operator+(int, const String&); String& operator++(); String& operator--(); String operator++(int); String operator--(int); friend ostream& operator<<(ostream&, const String&); int getLength(const char*); String substr(int, int); void print(); };
(By the way, this isn't the string class from the C++ library)
Thanks in advance!
-Ryan



2Likes
LinkBack URL
About LinkBacks



