fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base {
  5. public:
  6. virtual void who()=0;
  7. int s;
  8. // virtual void who() { // визначення віртуальної функції
  9. // cout << "Base"<<endl;
  10. // }
  11. };
  12.  
  13. class FirstD: public Base {
  14. public:
  15. void who() { // визначення who() для FirstD
  16. cout << "First derivation"<<endl;
  17. }
  18. };
  19.  
  20. class SecondD: public FirstD {
  21. public:
  22. void who() { // визначення who() для SecondD
  23. cout << "Second derivation"<<endl;
  24. }
  25. };
  26.  
  27. int main()
  28. {
  29. //Base base;
  30. FirstD fd;
  31. fd.who();
  32. SecondD sd;
  33. sd.who();
  34. // int x=5;
  35. // Base base;
  36. // base.who();
  37. // int *x1;
  38. // Base *y=NULL;
  39. // y=&base;
  40. // // y->who();
  41. // FirstD fd;
  42. // // fd.who();
  43. // y=&fd;
  44. // // y->who();
  45. // SecondD sd;
  46. // // sd.who();
  47. // y=&sd;
  48. // // y->who();
  49.  
  50. Base **y1=new Base*[3];
  51. y1[0]=&fd;
  52. y1[1]=&fd;
  53. y1[2]=&sd;
  54. for(int i=0;i<3;i++){
  55. y1[i]->who();
  56. }
  57.  
  58. // Base **q=new Base*[3];
  59.  
  60.  
  61.  
  62.  
  63. return 0;
  64. }
  65.  
  66.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
First derivation
Second derivation
First derivation
First derivation
Second derivation