类模板与函数模板区别1
作者:互联网
#include <iostream>
template<class typeName, class typeAge>
class Person
{
public:
Person(typeName name, typeAge age):
name(name),
age(age)
{}
void show()
{
std::cout << "name " << name << std::endl;
std::cout << "age " << age << std::endl;
}
protected:
typeName name;
typeAge age;
};
int main()
{
/* 语法错误 */
//Person p("furong", 10);
Person<std::string, int> p("furong", 10);
p.show();
return 0;
}
$ ./a.out
name furong
age 10
注:类模板只能显示指定类型方式
标签:furong,name,区别,age,show,Person,模板,函数 来源: https://www.cnblogs.com/zhangxuechao/p/16488878.html