Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3.  
  4.  
  5. struct Proxy {
  6.  
  7.     operator int() const { printf("proxy read\n"); return 0; }
  8.     void operator=(int p_value) { printf("equal assign\n"); }
  9. };
  10.  
  11. struct Base {
  12.  
  13.     const int operator[](int idx) const { printf("const read\n"); return 0; }
  14.     Proxy operator[](int idx) { return Proxy(); }
  15.  
  16. };
  17.  
  18.  
  19. int main(int argc,char *argv[]) {
  20.  
  21.     Base base;
  22.     const int v = (*((const Base*)&base))[1];
  23.     int g = base[1];
  24.     base[1]=2;
  25.     return v;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement