fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Foo {
  6. int x = 0;
  7. };
  8.  
  9. void func(Foo *const x, Foo *y) {
  10. x->x = 42;
  11. // x = y; // error: assignment of read-only parameter ‘x’
  12. }
  13.  
  14. int main() {
  15. Foo a;
  16. Foo b;
  17. cout << a.x << endl;
  18. func(&a, &b);
  19. cout << a.x << endl;
  20. }
Success #stdin #stdout 0s 2896KB
stdin
stdout
0
42