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. private:
  27. scoped_ptr& operator=(const scoped_ptr& ptr);
  28. //{
  29. // cout << "in scoped_ptr::operator=(const scoped_ptr&)" << endl;
  30. // pObj = ptr.pObj;
  31. // return *this;
  32. //}
  33. };
  34.  
  35. int main()
  36. {
  37. scoped_ptr p = new Object();
  38. p = new Object();
  39. return 0;
  40. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:27:17: error: ‘scoped_ptr& scoped_ptr::operator=(const scoped_ptr&)’ is private
prog.cpp:38:20: error: within this context
stdout
Standard output is empty