#include <iostream>
using namespace std;
struct Base {virtual int process(int a, int b) = 0;};
static struct : Base {
int process(int a, int b) { return a+b;}
} add;
static struct : Base {
int process(int a, int b) { return a-b;}
} subtract;
static struct : Base {
int process(int a, int b) { return a*b;}
} multiply;
static struct : Base {
int process(int a, int b) { return a/b;}
} divide;
void perform(Base& op, int a, int b) {
cout << "input: " << a << ", " << b << "; output: " << op.process(a, b) << endl;
}
int main() {
perform(add, 2, 3);
perform(subtract, 6, 1);
perform(multiply, 6, 7);
perform(divide, 72, 8);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IEJhc2Uge3ZpcnR1YWwgaW50IHByb2Nlc3MoaW50IGEsIGludCBiKSA9IDA7fTsKc3RhdGljIHN0cnVjdCA6IEJhc2UgewogICAgaW50IHByb2Nlc3MoaW50IGEsIGludCBiKSB7IHJldHVybiBhK2I7fQkKfSBhZGQ7CnN0YXRpYyBzdHJ1Y3QgOiBCYXNlIHsKICAgIGludCBwcm9jZXNzKGludCBhLCBpbnQgYikgeyByZXR1cm4gYS1iO30JCn0gc3VidHJhY3Q7CnN0YXRpYyBzdHJ1Y3QgOiBCYXNlIHsKICAgIGludCBwcm9jZXNzKGludCBhLCBpbnQgYikgeyByZXR1cm4gYSpiO30JCn0gbXVsdGlwbHk7CnN0YXRpYyBzdHJ1Y3QgOiBCYXNlIHsKICAgIGludCBwcm9jZXNzKGludCBhLCBpbnQgYikgeyByZXR1cm4gYS9iO30JCn0gZGl2aWRlOwoKdm9pZCBwZXJmb3JtKEJhc2UmIG9wLCBpbnQgYSwgaW50IGIpIHsKCWNvdXQgPDwgImlucHV0OiAiIDw8IGEgPDwgIiwgIiA8PCBiIDw8ICI7IG91dHB1dDogIiA8PCBvcC5wcm9jZXNzKGEsIGIpIDw8IGVuZGw7Cn0KCmludCBtYWluKCkgewoJcGVyZm9ybShhZGQsIDIsIDMpOwoJcGVyZm9ybShzdWJ0cmFjdCwgNiwgMSk7CglwZXJmb3JtKG11bHRpcGx5LCA2LCA3KTsKCXBlcmZvcm0oZGl2aWRlLCA3MiwgOCk7CglyZXR1cm4gMDsKfQ==