fork download
  1. #include <iostream>
  2. struct X {
  3. virtual void f() const { std::cout << "X"; }
  4. };
  5.  
  6. struct Y : public X {
  7. void f() const { std::cout << "Y"; }
  8. };
  9.  
  10. void print(const X &x) { x.f(); }
  11.  
  12. int main() {
  13. X arr[1];
  14. Y y1;
  15. arr[0] = y1;
  16. print(y1);
  17. print(arr[0]);
  18. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
YX