This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 10th, 2012  |  syntax: C++  |  size: 0.47 KB  |  views: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. extern "C" {
  2. #include <stdint.h>
  3. #include <netinet/in.h>
  4. #include <arpa/inet.h>
  5. }
  6.  
  7. class _getset_16 {
  8.     uint16_t* _x;
  9.     _getset_16() = delete;
  10. public:
  11.     _getset_16(uint16_t& x) : _x(&x) { }
  12.     operator uint16_t () const { return ntohs(*_x); }
  13.     _getset_16& operator = (uint16_t y) { *_x = htons(y); return *this; }
  14. };
  15.  
  16. class P {
  17.     uint16_t _x;
  18. public:
  19.     _getset_16 x() { return _getset_16(_x); }
  20. };
  21.  
  22. int main() {
  23.     P p;
  24.     p.x() = 2;
  25. }
clone this paste RAW Paste Data