fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Number
  5. {
  6. virtual ~Number() = default;
  7. };
  8.  
  9. struct Integer : Number
  10. {
  11. int num = 0;
  12. void sum(const Number& n)
  13. {
  14. num += static_cast<const Integer&>(n).num;
  15. }
  16. };
  17.  
  18.  
  19. int main()
  20. {
  21. Integer i1;
  22. i1.num = 31337;
  23. Integer i2;
  24. i2.num = 31338;
  25. i2.sum(i1);
  26. cout << i2.num << endl;
  27. return 0;
  28. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
62675