Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Abstract
  6. {
  7. protected:
  8.     double a;
  9. public:
  10.     Abstract(const double& a):a(a) {}
  11.     double GetA()const
  12.     {
  13.         return a;
  14.     }
  15.     void Sum(const Abstract &ab)
  16.     {
  17.         doSum(ab);
  18.     }
  19. private:
  20.     virtual void doSum(const Abstract &ab) = 0;
  21. };
  22. class Derived : public Abstract
  23. {
  24. public:
  25.     Derived(const double& a) :Abstract(a) {}
  26.     void doSum(const Abstract &der)
  27.     {
  28.         a += der.GetA();
  29.     }
  30. };
  31. int main()
  32. {
  33.     Derived object(2);
  34.     Derived object2(5);
  35.     object.Sum(object2);
  36.     cout << object.GetA() << endl;
  37.     system("pause");
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement