-
friend functions
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:
Code:
//This is the .h file
#include <iostream.h>
class String
{
public:
friend ostream& operator<<(ostream&, String&);
//.....
//.....
private:
char* lpzstr;
};
Then I define the function in the .cpp file like this :
Code:
ostream& operator<<(ostream& o, String& newStr)
{
return o << newStr.lpzstr;
}
Where should i define friend functions OR what am I doing
wrongly?
-
Try this:
Code:
ostream& operator<<(ostream& o, String& newString)
{
o<<newString.lpzstr;
return o;
}
-
Well what do you know, my original code works all of a sudden!!
I think it was perhaps my compiler(MSVC++ 6) OR it could be this
Vsual Assist Intellisense upgrade that's messing everything up!
But thanks anyway for your reply, i appreciate it vey much.;)