fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Command
  5. {
  6. virtual void Exe()
  7. { cout << "COMMAND" << endl; }
  8. };
  9.  
  10. struct NewCommand : Command
  11. {
  12. void Exe() final
  13. { cout << "NEW" << endl; }
  14.  
  15. void Xe() {cout << "EXTRA" << endl;}
  16. };
  17.  
  18. int main() {
  19. // your code goes here
  20. Command cmd1;
  21. NewCommand cmd2;
  22.  
  23. cmd1.Exe();
  24. cmd2.Exe();
  25. static_cast<Command>(cmd2).Exe();
  26. Command& cmd1p = cmd2;
  27. cmd1p.Exe();
  28. static_cast<NewCommand&>(cmd1p).Xe();
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5264KB
stdin
Standard input is empty
stdout
COMMAND
NEW
COMMAND
NEW
EXTRA