fork(3) download
  1. #include <iostream>
  2. #include <exception>
  3. #include <vector>
  4. #include <string>
  5. #include <iterator>
  6. #include <algorithm>
  7.  
  8. class base
  9. {
  10. public:
  11. base() = default;
  12. virtual ~base() = default;
  13.  
  14. void func()
  15. {
  16. std::cout << "base" << std::endl;
  17. }
  18.  
  19. virtual void g()
  20. {
  21. std::cout << "base::g" << std::endl;
  22. }
  23. };
  24.  
  25. class derived : public base
  26. {
  27. public:
  28. void func()
  29. {
  30. std::cout << "derived" << std::endl;
  31. }
  32.  
  33. void g() override
  34. {
  35. std::cout << "derived::g" << std::endl;
  36. }
  37.  
  38. void e()
  39. {
  40. std::cout << "derived:e" << std::endl;
  41. }
  42. };
  43.  
  44. void st(void)
  45. {
  46. static int x = 1;
  47. std::cout << x << std::endl;
  48. ++x;
  49. }
  50.  
  51. int main()
  52. {
  53. base b;
  54. derived d;
  55.  
  56. base& bRef = b;
  57. base& dRef = d;
  58.  
  59. bRef.g();
  60. dRef.g();
  61.  
  62. static_cast<derived&>(bRef).e();
  63.  
  64. return 0;
  65. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
base::g
derived::g
derived:e