using template in class
来源:互联网 发布:excel求竖排数据平均数 编辑:程序博客网 时间:2024/06/10 01:51
Today I studied using template in a class.The following is the code:
1.Header File: template.h:
#include <string>
using namespace std;
template <class T>class Cal
{
public:
Cal(){}
T Calculate(T&,T&);
};
2.CPP File: template.cpp
#include <iostream.h>
#include <stdio.h>
#include <string>
#include "template.h"
using namespace std;
template <class T>T Cal<T>::Calculate(T &t1,T &t2)
{
return t1+t2;
}
main()
{
Cal<int> *c=new Cal<int>();
int a=100;
int b=200;
cout<<c->Calculate(a,b)<<endl;
return 0;
}
最后执行结果如下图:
- using template in class
- An easy instance of using the template class in C++
- Implict conversion in template class
- function template application in class
- Callbacks In C++ Using Template Functors
- CALLBACKS IN C++ USING TEMPLATE FUNCTORS
- Using template in practice(实际运用)
- template class build errors in android
- Template Class
- template class
- template class
- class template
- template specialization on template class
- How to code the forward declaration of class or struct using template?
- Using C++ template metaprograms
- Heap & HeapSort (using template)
- Using Jinja Template
- Define Functions in Scala using Anonymous Inner Class
- 习惯
- 私人收藏
- Eclipse-COBOL程序员在WINDOWS平台上的IDE
- [Source Forge] Video & Audio 2
- 请问怎样实现FLASH+ASP留言板?
- using template in class
- 怎样快速查出Oracle 数据库中的锁等待
- 生活杂感
- FAQ:两种方法访问多层嵌套的frame
- 看看你的殺毒軟件有多強!
- Server的Transfer和Response的Redirect
- 头文件的使用
- 77777
- xml抓取繁体乱码正常显示的代码