Umm, my problem is this.
I have a friend function in my string class.
The class declaration in a .h file. The class implementation is in
a .cpp file.
If i define the friend function in the .cpp file i get this error :
<< is not a member of String
I want to overload the '<<' operator to provide printing for my
class. Here's what i'm doing:
Then I define the function in the .cpp file like this :Code://This is the .h file #include <iostream.h> class String { public: friend ostream& operator<<(ostream&, String&); //..... //..... private: char* lpzstr; };
Where should i define friend functions OR what am I doingCode:ostream& operator<<(ostream& o, String& newStr) { return o << newStr.lpzstr; }
wrongly?



LinkBack URL
About LinkBacks


