fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. struct S {
  6. std::string s_;
  7. static std::vector<S> tiles;
  8.  
  9. S() { std::cout << "S()\n"; init("default"); }
  10. S(const std::string& s) {
  11. std::cout << "S(" << (void*) this << " with " << s << ")\n";
  12. init(s);
  13. }
  14. S(const S& rhs) {
  15. std::cout << (void*) this << " copying " << (void*)&rhs << " (" << rhs.s_ << ")\n";
  16. s_ = rhs.s_;
  17. s_ += " copy";
  18. }
  19.  
  20. void init(const std::string& s) {
  21. s_ = s;
  22. std::cout << "init " << (void*)this << " " << s_ << "\n";
  23. tiles.push_back(*this); // makes copy
  24. }
  25. };
  26.  
  27.  
  28. std::vector<S> S::tiles = std::vector<S>(3);
  29.  
  30. int main() {
  31. for (const auto& el : S::tiles) {
  32. std::cout << el.s_ << "\n";
  33. }
  34. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
S()
init 0x9e67a10 default
0x9e67a10 copying 0x9e67a10 ()
S()
init 0x9e67a14 default
0x9e67a14 copying 0x9e67a14 ()
S()
init 0x9e67a18 default
0x9e67a18 copying 0x9e67a18 ()
 copy
 copy
 copy