fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Base {
  6. public:
  7. virtual string toString() const {
  8. return "base";
  9. }
  10. };
  11.  
  12. class Child : public Base {
  13. public:
  14. virtual string toString() const {
  15. return "child";
  16. }
  17.  
  18. friend ostream& operator<<(ostream& out, const Base& b);
  19. };
  20.  
  21. ostream& operator<<(ostream& out, const Base& b) {
  22. out << b.toString();
  23. return out;
  24. }
  25.  
  26. int main() {
  27. Child c;
  28. cout << c;
  29. return 0;
  30. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
child