SHARE
TWEET

Untitled

a guest Mar 10th, 2012 20 Never
  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. }
RAW Paste Data
Top