fork download
  1. #include <iostream>
  2.  
  3. struct Foo {
  4. Foo( int init )
  5. : value( init )
  6. { }
  7.  
  8. int value;
  9. };
  10.  
  11. int main() {
  12.  
  13. Foo foo( 2 );
  14. // write
  15. int new_values[] = { 1, 1, 1, 2, 3, 3 };
  16. size_t const size = sizeof(new_values) / sizeof(*new_values);
  17.  
  18. for( size_t i = 0; i != size; ++i ) {
  19. std::cout << "set in index: " << i << std::endl;
  20. foo.value = new_values[ i ];
  21. }
  22.  
  23. // read
  24. std::cout << "final value: " << foo.value << std::endl;
  25. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
set in index: 0
set in index: 1
set in index: 2
set in index: 3
set in index: 4
set in index: 5
final value: 3