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 OtherObject
  11. {
  12. public:
  13. operator Object*() { return new Object(); }
  14. };
  15.  
  16. class scoped_ptr
  17. {
  18. Object *pObj;
  19.  
  20. public:
  21. scoped_ptr(Object *pObject) : pObj(pObject)
  22. {
  23. cout << "in constructor scoped_ptr(Object*)" << endl;
  24. }
  25.  
  26. scoped_ptr(const scoped_ptr& ptr)
  27. {
  28. cout << "in constructor scoped_ptr(const scoped_ptr&)" << endl;
  29. pObj = ptr.pObj;
  30. }
  31.  
  32. scoped_ptr& operator=(const scoped_ptr& ptr)
  33. {
  34. cout << "in scoped_ptr::operator=(const scoped_ptr&)" << endl;
  35. pObj = ptr.pObj;
  36. return *this;
  37. }
  38. };
  39.  
  40. int main()
  41. {
  42. OtherObject oo;
  43. // OtherObject oo(); is again a function definition :)
  44. scoped_ptr p1(oo);
  45. return 0;
  46. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
in constructor Object()
in constructor scoped_ptr(Object*)