template<class T>
class person
{
public:
person(T id ,T age)
{
this->id=id;
this->age=age
}
void show()
{
cout<<this->id<<this->age<<endl;
}
public:
T id;
T age;
};
void test0()
{
//函数模板在调用的时候,可以自动类型推导,故不一定显式指定类型
person<int>P(10,20)//类模板必须显式指定类型(类模板的使用)
}
-----------类模板派生普通类----------
class Subperson:public person<int>//为什么加int 继承要开辟内存
{
};
-------------类模板派生模板类
template<class T>
class subperson:public person<T>{};
-----------c语言-------
#ifndef PERSON_H
#define PERSON_H
#endif
------------c++语言--------------------
#pragma one//防止头文件被重复包含
STL(类模板笔记)
最新推荐文章于 2024-02-23 16:12:12 发布