#include using namespace std;

template class BinOper{ private: T lop, rop; public: void setData(T value1, T value2){ lop = value1; rop = value2; } T add(){ return lop + rop; } T sub(){ return lop - rop; } void swap(){ T temp = lop; lop = rop; rop = temp; } };

int main(){ BinOper a; BinOper b; int d1,d2; cin>>d1>>d2; a.setData(d1,d2); b.setData(d1,d2); b.swap(); cout<<a.add()<<endl; cout<<b.sub()<<endl; return 0; }

C++模板类BinOper实现二元运算

原文地址: https://www.cveoy.top/t/topic/osKI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录