fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class One {
  5. public:
  6. virtual void id(const std::string &what = "I'm class One!") const
  7. {
  8. std::cout << "class One says: " << what << std::endl;
  9. }
  10.  
  11. virtual ~One()
  12. {
  13. }
  14. };
  15.  
  16. struct Two: One {
  17. void id(const std::string &what = "I'm struct Two!") const
  18. {
  19. std::cout << "struct Two says: " << what << std::endl;
  20. }
  21. };
  22.  
  23. int main()
  24. {
  25. One *o = new Two;
  26.  
  27. o->id();
  28. delete o;
  29. }
Success #stdin #stdout 0.02s 2856KB
stdin
Standard input is empty
stdout
struct Two says: I'm class One!