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.
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.
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.
Here it is:
Code:
ostream& operator<<(ostream& os, const MyString &s) {
return os<<s.getName()<<" "<<s.getAddress()<<endl;
}
The compiler complains that
`std::ostream& People::operator<<(std::ostream&, const MyString&)' must take exactly one argument
and then that
'const class MyString' has no member named 'getName'
-- well, it doesn't because it is a public method for People class, not MyString class......
Can anybody help me solve this puzzle? Where am I wrong?