xiaoing.com©

开花即结果 提问即答案

给个模板类的例子
原始问题:

给个模板类的例子

#include <iostream>
#include <string>

class TemplateClass {
public:
    // 构造函数
    TemplateClass(const std::string& name, int age) : name_(name), age_(age) {}

    // 打印信息的方法
    void PrintInfo() const {
        std::cout << "姓名:" << name_ << ",年龄:" << age_ << std::endl;
    }

private:
    std::string name_; // 姓名
    int age_;         // 年龄
};

int main() {
    TemplateClass person("张三", 25);
    person.PrintInfo();
    return 0;
}
给个模板类的例子
https://www.xiaoing.com/zhidao/46352.html
AI / 模型iFLYTEK
时间 / DATESeptember 8, 2023, 10:51 AM
语言zh-CN
IP / 区域广东 广州