Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Binary_Operator
- {
- public:
- //virtual double evaluate(double a, double b) const { return 0.0; }
- virtual double evaluate(double a, double b) const = 0;
- };
- class Multiply : public Binary_Operator
- {
- public:
- double evaluate(double a, double b) const override { return a * b; }
- };
- class Add : public Binary_Operator
- {
- public:
- double evaluate(double a, double b) const override { return a + b; }
- };
- int main()
- {
- //vector<Binary_Operator> v{ Multiply{}, Add{} };
- vector<Binary_Operator*> v{ new Multiply{}, new Add{} };
- for ( int i{0}; i < v.size(); ++i )
- {
- //cout << v[0].evaluate(5.0, 3.0) << endl;
- cout << v[i].evaluate(5.0, 3.0) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment