fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Object
  5. {
  6. public:
  7. Object() { cout << "in constructor Object()" << endl; }
  8. };
  9.  
  10. class scoped_ptr
  11. {
  12. Object *pObj;
  13.  
  14. public:
  15. scoped_ptr(Object *pObject) : pObj(pObject)
  16. {
  17. cout << "in constructor scoped_ptr(Object*)" << endl;
  18. }
  19.  
  20. scoped_ptr(const scoped_ptr& ptr)
  21. {
  22. cout << "in constructor scoped_ptr(const scoped_ptr&)" << endl;
  23. pObj = ptr.pObj;
  24. }
  25.  
  26. scoped_ptr& operator=(const scoped_ptr& ptr) = delete;
  27. //{
  28. // cout << "in scoped_ptr::operator=(const scoped_ptr&)" << endl;
  29. // pObj = ptr.pObj;
  30. // return *this;
  31. //}
  32. };
  33.  
  34. int main()
  35. {
  36. scoped_ptr p = new Object();
  37. p = new Object();
  38. return 0;
  39. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:37:20: error: use of deleted function ‘scoped_ptr& scoped_ptr::operator=(const scoped_ptr&)’
prog.cpp:26:17: error: declared here
stdout
Standard output is empty