#include <iostream>
#include <string>
using namespace std;
// 习惯性 < >中 类模板用class 普通的函数模板就用typename
// template<class NAMETYPE, class AGETYPE>
template<class NAMETYPE, class AGETYPE = int> // 可以设置默认的类型值,后面在使用的时候,就不用再指定类型了
class Students06{
public:
    NAMETYPE m_name;
    AGETYPE m_age;
    Students06(NAMETYPE name, AGETYPE age){
        this->m_name = name;
        this->m_age = age;
    }
    void show(){
        cout << "姓名: " << this->m_name << endl;
        cout << "年龄: " << this->m_age << endl;
    }
};
int main()
{
    // 1.类模板 无法使用自动类型推导
    // Students06 stu1("张三",100);
    // 2.显示指定类型
    // Students06<string, int> stu1("张三",18);
    Students06<string> stu1("张三",18); // 可以设置默认的类型值,在使用的时候,就不用再指定类型了
    stu1.show();
    return 0;
}
类模板基本概念
类模板和函数模板的定义和使用类似,我们已经进行了介绍。有时,有两个或多个类,其功能是相同的,仅仅是数据类型不同。
- 类模板用于实现类所需数据的类型参数化










![【YOLOv9改进[注意力]】在YOLOv9中使用注意力CascadedGroupAttention(2023)的实践 + 含全部代码和详细修改方式](https://img-blog.csdnimg.cn/direct/337847fd86bd4ebf8a9228e4e4065a10.png)







