标签:根据 vat 影响 ble 缺点 特性 ide bsp 输入
1 #include <iostream> 2 using namespace std; 3 4 class COperation{ 5 public: 6 int A,B; 7 virtual double GetResult(){ 8 double dResult = 0; 9 return dResult; 10 } 11 }; 12 13 // 加法 14 class AddOperation:public COperation{ 15 public: 16 virtual double GetResult(){ 17 return A + B; 18 } 19 }; 20 // 减法 21 class SubOperation:public COperation{ 22 public: 23 virtual double GetResult(){ 24 return A - B; 25 } 26 }; 27 // 工厂类 28 class CCalculatorFactory{ 29 public: 30 static COperation *Create(char cOperator); 31 }; 32 33 COperation* CCalculatorFactory::Create(char cOperator){ 34 COperation *oper; 35 switch(cOperator){ 36 case ‘+‘: 37 oper = new AddOperation(); 38 break; 39 case ‘-‘: 40 oper = new SubOperation(); 41 break; 42 default: 43 oper = new AddOperation(); 44 break; 45 } 46 return oper; 47 } 48 49 int main(){ 50 int a,b; 51 cin>>a>>b; 52 COperation* op = CCalculatorFactory::Create(‘+‘); 53 op->A = a; 54 op->B = b; 55 cout << op->GetResult() << endl; 56 return 0; 57 }
标签:根据 vat 影响 ble 缺点 特性 ide bsp 输入
原文地址:https://www.cnblogs.com/cxc1357/p/12249376.html