template类
来源:互联网 发布:tensorflow人脸关键点 编辑:程序博客网 时间:2024/06/06 03:57
在工程中应将声明和定义分开
并置于头文件中
#include<iostream>
using namespace std;
template<typename T>
class Operator{
public:
T add(T a,T b); //要将声明和定义分开
T minus(T a,T b);
};
using namespace std;
template<typename T>
class Operator{
public:
T add(T a,T b); //要将声明和定义分开
T minus(T a,T b);
};
template<typename T> //必须加template 声明
T Operator<T>::add(T a,T b) //<T>不可少
{
return a+b;
}
T Operator<T>::add(T a,T b) //<T>不可少
{
return a+b;
}
template<typename T>
T Operator<T>::minus(T a,T b)
{
return a-b;
}
T Operator<T>::minus(T a,T b)
{
return a-b;
}
int main()
{
Operator<int> op1;
cout<<op1.add(5,6)<<endl;
Operator<float> op2;
cout<<op2.minus(3.14,1.22)<<endl;
return 0;
}
{
Operator<int> op1;
cout<<op1.add(5,6)<<endl;
Operator<float> op2;
cout<<op2.minus(3.14,1.22)<<endl;
return 0;
}
0 0
- template类
- template函数和template类
- C++ template - 类模板
- template 模板类
- c++ template 类模板
- C++类模板template
- 类模板-template
- C++模板类template
- template模板类使用
- 类模板Template
- C++类模板template
- template
- Template
- template
- template
- template
- Template
- template
- 7,词根 - 倒、流
- Java API 与HBase交互实例(二)
- Qt将图片保存为XML文件或者变为QSting
- linux配置java环境变量(详细)
- php规范一种字符串
- template类
- 学生个性
- git(一)
- 菜鸟级springmvc+spring+mybatis整合开发用户登录功能(下)
- Linux基础知识和常用命令(一)
- Chapter 9 模板方法模式
- Canvas绘制弧线(打钩、打叉)动画示例及怎样封装成移动端javascript插件(一)
- 字符串问题(四)
- Oracle更新表字段时内容中含有特殊字符&的解决方法