SHARE
TWEET

Untitled

a guest Jun 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top