Jommiey

Lektion3_4

Nov 19th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. class Binary_Operator
  2. {
  3. public:
  4.   //virtual double evaluate(double a, double b) const { return 0.0; }
  5.   virtual double evaluate(double a, double b) const = 0;
  6.  
  7. };
  8.  
  9. class Multiply : public Binary_Operator
  10. {
  11. public:
  12.   double evaluate(double a, double b) const override { return a * b; }
  13. };
  14.  
  15. class Add : public Binary_Operator
  16. {
  17. public:
  18.   double evaluate(double a, double b) const override { return a + b; }
  19. };
  20.  
  21. int main()
  22. {
  23.   //vector<Binary_Operator> v{ Multiply{}, Add{} };
  24.   vector<Binary_Operator*> v{ new Multiply{}, new Add{} };
  25.  
  26.   for ( int i{0}; i < v.size(); ++i )
  27.   {
  28.     //cout << v[0].evaluate(5.0, 3.0) << endl;
  29.     cout << v[i].evaluate(5.0, 3.0) << endl;
  30.   }
  31.   return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment