fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class test
  5. {
  6. private:
  7. ~test()
  8. {
  9. cout<<"destrucor called";
  10. }
  11. friend void desturct (test*);
  12. };
  13. void destruct (test *obj)
  14. {
  15. delete obj;
  16. cout<<"destrucor called1";
  17. }
  18. int main()
  19. {
  20. test *obj = new test;
  21. destruct(obj);
  22.  
  23. return 0;
  24. }
Compilation error #stdin compilation error #stdout 0s 4400KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void destruct(test*)’:
prog.cpp:15:10: error: ‘test::~test()’ is private within this context
   delete obj;
          ^~~
prog.cpp:7:2: note: declared private here
  ~test()
  ^
stdout
Standard output is empty