void Customer::operator << (const Customer &right)
{
print();
}
is indeed wrong. Those operators are meant to be "injected" into the stream classes with something like this declaration:
friend ostream& operator<< (ostream& os, const Customer& cust);
and you define it with something like:
ostream& operator<< (ostream& os, const Customer& cust)
{
os << cust.someField; // this bit is customised per your needs.
return os;
}
For your particular case, it would probably be something along the lines of:
os << "[custnum=" << custNum
<< ",name=" << name
<< ",address=" << address
<< "]";
Note that your print()
member function is useless for generalised printing since it's tied to cout
. Those operators should be available to any stream.