Advertisement
ANCHI22

practice polimorfismo, herencia, opp

Mar 29th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5.     public:
  6.     virtual int calcula (){
  7.         return 1;
  8.     };
  9. };
  10.  
  11.  
  12. class B:public A{
  13.     public:
  14.     virtual int calcula (){
  15.         return 2;
  16.     }
  17. };
  18.  
  19. class C:public B{
  20.     public:
  21.     virtual int calcula (){
  22.         return 3;
  23.     }
  24. };
  25.  
  26. int main () {
  27.    int Result = 0;
  28.    A *Objs [3];
  29.    Objs [0] = new A ();
  30.    Objs [1] = new B ();
  31.    Objs [2] = new C ();
  32.    for (int i = 0; i <3; i ++)
  33.          Result += Objs [i] -> calcula ();
  34.     cout << Result << endl;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement