fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. template <typename T>
  5. class A
  6. {
  7. T a;
  8. T b;
  9. public:
  10. A(T a, T b): a(a), b(b) {}
  11. void show() {
  12. std::cout << a << b << std::endl;
  13. }
  14. };
  15.  
  16. class B
  17. {
  18. std::shared_ptr<A<int>> ptr = nullptr;
  19.  
  20. void foo()
  21. {
  22. ptr = std::make_shared<A<int>>(1, 2);
  23. }
  24.  
  25. public:
  26. void bar()
  27. {
  28. foo();
  29. ptr->show();
  30. }
  31.  
  32. };
  33.  
  34. int main()
  35. {
  36. B b;
  37. b.bar();
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 4272KB
stdin
Standard input is empty
stdout
12