fork download
  1. struct virt_z {
  2. double x;
  3. double y;
  4. struct z_wrap {
  5. virt_z &parent;
  6.  
  7. operator double() { return parent.x * parent.y; }
  8. z_wrap &operator=( double in ) {
  9. parent.x = in;
  10. parent.y = 1;
  11. return *this;
  12. }
  13. z_wrap( virt_z &in ) : parent( in ) {}
  14. } z;
  15.  
  16. virt_z() : z( *this ) {}
  17. virt_z( virt_z const &o ) : x( o.x ), y( o.y ), z( *this ) {}
  18. };
  19.  
  20. #include <iostream>
  21.  
  22. int main() {
  23. virt_z xyz;
  24. xyz.x = 5;
  25. xyz.y = 2;
  26. std::cout << xyz.z << '\n';
  27. xyz.z = 8;
  28. std::cout << xyz.x << ' ' << xyz.y << ' ' << xyz.z << '\n';
  29. }
  30.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
10
8 1 8