fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <memory>
  4. #include <functional>
  5.  
  6. struct OBJ
  7. {
  8. OBJ()
  9. {
  10. std::cout << __PRETTY_FUNCTION__ << '\n';
  11. }
  12.  
  13. ~OBJ()
  14. {
  15. std::cout << __PRETTY_FUNCTION__ << '\n';
  16. }
  17. };
  18.  
  19.  
  20. class client
  21. {
  22. private:
  23. struct deleter
  24. {
  25. deleter(client *pThis) : pThis(pThis) {}
  26. void operator()(OBJ* p) { pThis->del_obj(p); }
  27.  
  28. private:
  29. client *pThis;
  30. };
  31.  
  32. void del_obj(OBJ* p)
  33. {
  34. delete p;
  35. }
  36.  
  37. std::unique_ptr<OBJ, deleter> objptr;
  38.  
  39. public:
  40. client() : objptr(new OBJ, deleter(this))
  41. {
  42. }
  43. };
  44.  
  45. int main()
  46. {
  47. client cli;
  48. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
OBJ::OBJ()
OBJ::~OBJ()