I wrote a class called MyString. It uses NTS string, c-style. Basically consists of constructors, copy constructor and destructor. Nothing else.
I also wrote another class, called People.
I need to write a show() method in this class which will display all its private members...... Here I encountered problems. First it did not compile , it complained that << does not defined in there. OK, so I tried to write a method overloading the operator << to display MyString types data members.Code:class People { private: MyString name; MyString address; int age; public: // methods such as constructors asking user to provide // all the info to instantiate an object. Did not have a problem // with assigning values to MyString name or MyString address.
Here it is:
The compiler complains thatCode:ostream& operator<<(ostream& os, const MyString &s) { return os<<s.getName()<<" "<<s.getAddress()<<endl; }
and then that`std::ostream& People::operator<<(std::ostream&, const MyString&)' must take exactly one argument
-- well, it doesn't because it is a public method for People class, not MyString class......'const class MyString' has no member named 'getName'
Can anybody help me solve this puzzle? Where am I wrong?



LinkBack URL
About LinkBacks


