fork(1) download
  1. #include <iostream>
  2.  
  3. class Base
  4. {
  5. public:
  6. Base() { std::cout << "Base defCtor" << std::endl; }
  7. Base(const Base& rhs) { std::cout << "Base copyCotr" << std::endl; }
  8. virtual Base* clone() { return new Base(*this); }
  9. };
  10.  
  11. class Derived : public Base
  12. {
  13. public:
  14. Derived() { std::cout << "Derived defCtor" << std::endl; }
  15. Derived(const Derived& rhs) : Base(rhs)
  16. { std::cout << "Derived copyCotr" << std::endl; }
  17. virtual Derived* clone() { return new Derived(*this); }
  18. };
  19.  
  20. int main()
  21. {
  22. Base *bp = new Derived;
  23. Base *bq = bp->clone();
  24. return 0;
  25. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
Base defCtor
Derived defCtor
Base copyCotr
Derived copyCotr