#include <iostream>
using namespace std;
template <typename T>
class classA{
public:
classA(T a)
{
this->a = a;
}
void print()
{
cout << "a= " << this->a << endl;
}
private:
T a;
};
/*模板类做函数参数*/
void stage(classA<char> &oop)
{
oop.print();
}
int main(void)
{
classA<int> oop(100);
oop.print();
classA <char> oop1('Z');
stage(oop1);
system("pause");
return 0;
}
注意:void stage(classA<char> &oop) 模板类做函数参数时一定要加上传递的参数类型。
C++模板类
猜你喜欢
转载自blog.csdn.net/Linux_bin/article/details/77924638
今日推荐
周排行