类模板与函数模板区别2
作者:互联网
#include <iostream>
template<class typeName, class typeAge = int>
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<std::string> p("furong", 10);
p.show();
return 0;
}
$ ./a.out
name furong
age 10
注:类模板中,模板参数列表可以有默认参数
标签:furong,name,区别,age,show,Person,模板,函数 来源: https://www.cnblogs.com/zhangxuechao/p/16488887.html