fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. struct S
  5. {
  6. S()
  7. {
  8. std::cout << "Constructed!" << std::endl;
  9. }
  10.  
  11. S(const S&)
  12. {
  13. std::cout << "Copied!" << std::endl;
  14. }
  15.  
  16. double d[10];
  17. };
  18.  
  19. int main()
  20. {
  21. std::cout << "here we begin the show" << std::endl;
  22. std::basic_string<S> s1;
  23. std::cout << "lets resize" << std::endl;
  24. s1.resize(5);
  25. s1[2].d[2] = 1;
  26. std::cout << "lets copy" << std::endl;
  27. std::basic_string<S> s2(s1);
  28. std::cout << "lets modify" << std::endl;
  29. s2[2].d[2] = 3;
  30. std::cout << "lets print" << std::endl;
  31. std::cout << s1[2].d[2] << std::endl;
  32. std::cout << s2[2].d[2] << std::endl;
  33. }
  34.  
Success #stdin #stdout 0.01s 2864KB
stdin
Standard input is empty
stdout
Constructed!
here we begin the show
lets resize
Constructed!
Copied!
Copied!
Copied!
lets copy
lets modify
lets print
1
3