T
Tim Partridge
I want operator<< to be a friend function of a class inside a namespace, but
I don't know how. For example:
#include <iostream>
namespace ns {
class foo {
public:
// there is something wrong with the line below, but I don't
know how to fix it. I think I need to
// specify the namespace and class for the operator<<, but if I
write std:stream:perator<<
// i get all sorts of errors I don't understand.
friend std:stream& operator<<( std:stream &stream, const foo
&f );
private:
int i;
};
}
std:stream& operator<<( std:stream &stream, const ns::foo &f ) {
stream << f.i; // compiler complains i is private
return stream;
}
int main(int argc, char* argv[]) {
return 0;
}
I don't know how. For example:
#include <iostream>
namespace ns {
class foo {
public:
// there is something wrong with the line below, but I don't
know how to fix it. I think I need to
// specify the namespace and class for the operator<<, but if I
write std:stream:perator<<
// i get all sorts of errors I don't understand.
friend std:stream& operator<<( std:stream &stream, const foo
&f );
private:
int i;
};
}
std:stream& operator<<( std:stream &stream, const ns::foo &f ) {
stream << f.i; // compiler complains i is private
return stream;
}
int main(int argc, char* argv[]) {
return 0;
}