Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Passing by reference - operator overloading [closed]
  2. int a = 1;
  3. int b = 2;
  4. int c = a + b;
  5.        
  6. UserType e = ...;
  7. UserType d = ...;
  8. UserType f = e + d;
  9.        
  10. struct IpAddress
  11. {
  12.     unsigned int addr;
  13. };
  14.        
  15. ostream& operator<<(ostream& os, const IpAddress& ip)
  16. {
  17.     os
  18.         << (ip.addr >> 24) << '.'
  19.         << (0xff & (ip.addr >> 16)) << '.'
  20.         << (0xff & (ip.addr >> 8)) << '.'
  21.         << (0xff & ip.addr);
  22.  
  23.     return os;
  24. }
  25.        
  26. IpAddress ip;
  27. // put something to ip
  28.  
  29. cout << "your address is: " << ip << endl;
  30.  
  31. ofstream f("log.txt");
  32. f << "address: " << ip << endl;