范文无忧网范文学习范文大全

设计一个类模版C

01月07日 编辑 fanwen51.com

//根据题意写了下面的程序,测试通过,有疑问欢迎讨论#includeusing namespace std;templateclass MathOper{private: Dtype tar1; Dtype tar2;public: MathOper(Dtype tar1, Dtype tar2){ this->tar1 = tar1; this->tar2 = tar2; } void SetTars(Dtype tar1, Dtype tar2){ //设置成员变量的值 this->tar1 = tar1; this->tar2 = tar2; } Dtype add(){ return tar1 + tar2; }};int main(){ int a = 2, b = 2; MathOpertar(a ,b);//for int printf("%d\n", tar.add()); MathOpertar_c('A', 'B'); //for char printf("%c\n", tar_c.add()); //output result return 0;}...

推荐阅读
图文推荐
栏目列表