fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Base {
  5. public:
  6. virtual int function() const {
  7. cout << "Base::function()\n";
  8. return 1;
  9. }
  10. virtual void function(string) const {}
  11. };
  12.  
  13.  
  14. class Derived : public Base {
  15. public:
  16. // overloading function() of base
  17. int function(int) const {
  18. cout << "Derived::function()\n";
  19. return 4;
  20. }
  21. };
  22.  
  23.  
  24. int main()
  25. {
  26. string s("StackOverflow");
  27. Derived d;
  28. Base* b = &d;
  29. //calling derived::function() and function(s)
  30. b->function();
  31. b->function(s);
  32. }
  33.  
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
Base::function()