fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. class B{
  8. public:
  9. B(){
  10. cout << "BC" << endl; x = 0;
  11. }
  12. virtual ~B(){
  13. cout << "BD" << endl;
  14. }
  15. void f(){
  16. cout << "BF" << endl;
  17. }
  18. virtual void g(){
  19. cout << "BG" << endl;
  20. }
  21. private:
  22. int x; };
  23.  
  24.  
  25.  
  26. class D: public B{
  27. public:
  28. D(){
  29. cout << "dc" << endl; y = 0;
  30. }
  31. virtual ~D(){
  32. cout << "dd" << endl;
  33. }
  34. void f(){
  35. cout << "df" << endl;
  36. }
  37. virtual void g(){
  38. cout << "dg" << endl;
  39. }
  40. private:
  41. int y; };
  42.  
  43. int main(){
  44. B b;
  45. B *bp = &b;
  46. D d;
  47. D *dp = &d;
  48. bp->f();
  49. bp->g();
  50. bp = dp;
  51. bp->f();
  52. bp->g();
  53. }
Success #stdin #stdout 0s 3300KB
stdin
Standard input is empty
stdout
BC
BC
dc
BF
BG
BF
dg
dd
BD
BD