Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. struct X
  2. {
  3. int a;
  4. };
  5.  
  6. X getX();
  7.  
  8. void modify(const X& x)
  9. {
  10. const_cast<X&>(x).a++;
  11. }
  12.  
  13. int foo()
  14. {
  15. X x0 = getX();
  16. const X x1 = getX();
  17. const X& x2 = getX();
  18.  
  19. // Legal!
  20. modify(x0);
  21.  
  22. // Illegal!
  23. //modify(x1);
  24.  
  25. // Legal?
  26. modify(x2);
  27.  
  28. return x0.a + x1.a + x2.a;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement