fork download
  1. //
  2. // What is it about ?
  3. //
  4.  
  5. #include <iostream>
  6. #include <string>
  7. #include <memory>
  8. #include <vector>
  9.  
  10. using namespace std;
  11. struct A {
  12. A() : i(std::make_shared<std::vector<std::shared_ptr<int>>>()) {}
  13.  
  14. A(const A &other) {
  15. i = other.i;
  16. }
  17.  
  18. std::shared_ptr<std::vector<std::shared_ptr<int>>> i;
  19. };
  20.  
  21. struct B : public A {
  22. B(const A &other) : A(other) {}
  23. };
  24.  
  25. int main(int ac, char**av)
  26. {
  27. cout << "...\n";
  28.  
  29. { // throw
  30. A a;
  31. B b(a);
  32.  
  33. b.i->emplace_back(std::make_shared<int>(10));
  34. printf("%d\n", *a.i->at(0));
  35. }
  36.  
  37.  
  38. //cin.ignore(SIZE_MAX, '\n');
  39. cout << "Press Enter";
  40. cin.get();
  41. return 0;
  42. }
Success #stdin #stdout 0s 3280KB
stdin
Standard input is empty
stdout
...
10
Press Enter