fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. class Base
  6. {
  7. public:
  8. Base()
  9. {
  10. cout<<"Constructor"<<endl;
  11. }
  12. Base(const Base& rhs)
  13. {
  14. cout<<"Copy constructor"<<endl;
  15. }
  16. Base* Clone()
  17. {
  18. return new Base(*this);
  19. }
  20. void* operator new(size_t size)
  21. {
  22. void* p=malloc(size);
  23. cout<<"Inside new"<<endl;
  24. return p;
  25. }
  26. };
  27.  
  28. int main()
  29. {
  30. Base b1;
  31. Base* ptr=b1.Clone();
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
Constructor
Inside new
Copy constructor