1、指定傳入型別
直接顯示物件的資料型別
2、引數模板化
將物件中的引數變為模板進行傳遞
3、整個類别範本化
將這個物件型別模板化進行傳遞
下面以**的形式做一個簡單案例。
#include
using
namespace std;
template
<
classt1,
class
t2>
class
person
void
showperson()
t1 m_name;
t2 m_age;};*
//1、指定傳入型別*
void
printperson1
(personint>
&p)void
test01()
//2、引數模板化
template
<
classt1,
class
t2>
void
printperson2
(person
&p)void
test02()
//3、整個類别範本化
template
<
class
t>
void
printperson3
( t &p)
void
test03()
intmain()