fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct My {
  5. int x;
  6. My(void): x(42) { std::cout << "Constructed: " << this << std::endl; }
  7. My(My const &m): x(m.x) { std::cout << "Copy constructed: " << this << std::endl; }
  8. ~My(void) { x = 0; std::cout << "Destructed: " << this << std::endl; }
  9. };
  10.  
  11. int main(void) {
  12. for(My const &i: {My(), My(), My()}) {
  13. std::cout << i.x << std::endl;
  14. }
  15.  
  16. return 0;
  17. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
Constructed: 0xbfdf13d4
Constructed: 0xbfdf13d8
Constructed: 0xbfdf13dc
42
42
42
Destructed: 0xbfdf13dc
Destructed: 0xbfdf13d8
Destructed: 0xbfdf13d4