
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 0.57 KB | hits: 9 | expires: Never
Passing by reference - operator overloading [closed]
int a = 1;
int b = 2;
int c = a + b;
UserType e = ...;
UserType d = ...;
UserType f = e + d;
struct IpAddress
{
unsigned int addr;
};
ostream& operator<<(ostream& os, const IpAddress& ip)
{
os
<< (ip.addr >> 24) << '.'
<< (0xff & (ip.addr >> 16)) << '.'
<< (0xff & (ip.addr >> 8)) << '.'
<< (0xff & ip.addr);
return os;
}
IpAddress ip;
// put something to ip
cout << "your address is: " << ip << endl;
ofstream f("log.txt");
f << "address: " << ip << endl;