fork download
  1.  
  2. #include <iostream>
  3. using std::cout;
  4. using std::endl;
  5.  
  6. #include <memory>
  7.  
  8. struct Base {
  9. Base() { cout << "b" << endl; }
  10. virtual ~Base() { cout << "~b" << endl; }
  11. };
  12.  
  13. struct Derived : Base {
  14. Derived() { cout << "d" << endl; }
  15. ~Derived() { cout << "~d" << endl; }
  16. };
  17.  
  18. int main() {
  19. std::shared_ptr<Base> pB;
  20. {
  21. std::shared_ptr<Derived> pD(new Derived);
  22. pB = pD;
  23. cout << "End of Block" << endl;
  24. }
  25. cout << "End of Main" << endl;
  26. }
  27.  
Success #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
b
d
End of Block
End of Main
~d
~b