compilation error when I overload cout operator inside the class
What I am missing?
Here after the source code. The problem disappear when I define the overload operator outside the class
#include <iostream>
using namespace std;
class Box {
public:
int l, b, h;
Box(int length, int breadth, int height) : l(length), b(breadth), h(height) {}
#if 1
ostream& operator<<(ostream& os) {
os << (l * b * h);
return os;
}
#endif
};
#if 0
ostream& operator<<(ostream& os, Box inb) {
os << (inb.l * inb.b * inb.h);
return os;
}
#endif
int main(void) {
Box B(3,4,5);
cout << B << endl;
return 0;
}