fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Person
  5. {
  6. virtual void id() const{
  7. cout << "PERSON::ID" << endl;
  8. }
  9. };
  10.  
  11. struct Student: Person
  12. {
  13. void id() const{
  14. cout << "STUDENT::ID" << endl;
  15. }
  16. };
  17.  
  18. int main() {
  19. Student s;
  20. Person *p = &s ;
  21. p->id();
  22. Person n;
  23. p = &n;
  24. p->id();
  25. return 0;
  26. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
STUDENT::ID
PERSON::ID