当前位置: 首页 > news >正文

类模板成员函数类外实现

#include<iostream>
#include<string>
using namespace std;//类模板成员函数类外实现 template<class T1,class T2>
class Person 
{
public:Person(T1 name,T2 age);
//	{
//		this->m_name=name;
//		this->m_age=age;
//	}void showPerson();
//	{
//		cout<<this->m_name<<' '<<this->m_age<<endl;
//	}T1 m_name;T2 m_age;};
//类外实现
template<class T1,class T2>
Person<T1,T2>::Person(T1 name,T2 age)
{this->m_name=name;this->m_age=age;
} template<class T1,class T2>
void Person<T1,T2>::showPerson()
{cout<<this->m_name<<' '<<this->m_age<<endl;
}void test01()
{Person<string,int>p("lyf",18);p.showPerson(); 
}
int main()
{test01();
} 

http://www.lryc.cn/news/235410.html

相关文章:

  • 多svn仓库一键更新脚本分享
  • C语言程序设计(入门)
  • 短视频账号矩阵系统源码
  • 基于SSM的在线投稿系统设计与实现
  • PWM实验
  • Python武器库开发-flask篇之session与cookie(二十六)
  • 深度学习YOLO安检管制物品识别与检测 - python opencv 计算机竞赛
  • vite+react+typescript 遇到的问题
  • 数据结构及八种常用数据结构简介
  • 阿里云配置ssl(Apache)
  • 阿里云linux升级新版本npm、nodejs
  • 如何在el-tree懒加载并且包含下级的情况下进行数据回显-02
  • Pytorch 网络冻结的三种方法区别:detach、requires_grad、with_no_grad
  • 如何定位el-tree中的树节点当父元素滚动时如何定位子元素
  • 【WiFI问题自助】解决WiFi能连上但是没有网的问题
  • 论文阅读:JINA EMBEDDINGS: A Novel Set of High-Performance Sentence Embedding Models
  • 计数排序.
  • flink中配置Rockdb的重要配置项
  • 代码随想录二刷 | 数组 | 有序数组的平方
  • 基于单片机C51全自动洗衣机仿真设计
  • 「Verilog学习笔记」实现3-8译码器①
  • Centos(Linux)服务器安装Dotnet8 及 常见问题解决
  • 最强人工智能ChatGPT引领AIGC发展
  • 10.Oracle的同义词与序列
  • 【周报2023-11-10】
  • 搜维尔科技:业内普遍选择Varjo头显作为医疗VR/AR/XR解决方案
  • 数据结构02附录01:顺序表考研习题[C++]
  • ClientDateSet:Cannot perform this operation on a closed dataset
  • python中列表的基础解释
  • 『力扣刷题本』:链表分割