fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class interface_d
  5. {
  6. public:
  7. virtual ~interface_d() {}
  8. };
  9.  
  10. class d1
  11. : public interface_d
  12. {
  13. public:
  14. d1() : interface_d(), m_x(new int) {}
  15. virtual ~d1()
  16. {
  17. delete m_x;
  18. }
  19.  
  20. private:
  21. int *m_x;
  22. };
  23.  
  24. class base
  25. {
  26. public:
  27. base(interface_d *impl) : m_impl(impl) {}
  28. virtual ~base()
  29. {
  30. // ... do something before clear impl
  31. delete m_impl;
  32. // ... do something after clear impl
  33. }
  34.  
  35. private:
  36. interface_d *m_impl;
  37. };
  38.  
  39. int main() {
  40. base x(new d1);
  41. return 0;
  42. }
Success #stdin #stdout 0s 3424KB
stdin
Standard input is empty
stdout
Standard output is empty