C++------クラステンプレートを関数パラメータとする
1292 ワード
#include
#include
// :string string.h ;
using namespace std;
// :
template
class Person
{
public:
Person(NameType name, AgeType age)
{
this->m_Age = age;
this->m_Name = name;
}
void showPerson()
{
cout << " :" << this->m_Name << " :" << this->m_Age << endl;
}
AgeType m_Age;
NameType m_Name;
};
//1. :
void do_work(Person & p)
{
p.showPerson();
}
void test01()
{
Person p1("sadjk", 100);
do_work(p1);
}
// , ;
//2. :
template
void do_work2(Person & p)
{
// :
cout << typeid(T1).name() << endl;
cout << typeid(T2).name() << endl;
p.showPerson();
}
void test02()
{
Personp2("sadsd", 90);
do_work2(p2);
}
//3. :
template
void do_work3(T& p)
{
cout << typeid(T).name() << endl;
p.showPerson();
}
void test03()
{
Person p3("asdasd", 907);
do_work3(p3);
}
int main()
{
test01();
test02();
test03();
return 0;
}