普通类的模板成员函数
发布日期:2021-07-21 18:10:34
浏览次数:2
分类:技术文章
本文共 498 字,大约阅读时间需要 1 分钟。
普通类的模板成员函数也挺重要的,有时候可以用用。
#include<iostream>
using namespace std; class A { public: template<class T> void fun(T t) { cout<<t<<endl; } }; void main() { A a; int i=32; double d=32.32; a.fun(i); a.fun(d); }以上模板成员函数的定义与实现在一起。
下面的模板成员函数定义与实现是分开的,这样也可以(以前老的编译器不支持这样的,不过现在的编译器都支持了)
#include<iostream>
using namespace std;class A{
public: template<class T> void fun(T t); };template <class T>
void A::fun(T t) { cout<<t<<endl; } int main(){ A a; int i=32; double d=32.32; a.fun(i); a.fun(d); return 1; }
转载地址:https://blog.csdn.net/lsg32/article/details/8870999 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2024年04月06日 08时20分36秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
nyoj动物统计字典树
2019-04-26
操作系统模拟生产者消费者问题
2019-04-26
JavaWeb的
2019-04-26
如何用JAVA爬取AJAX加载后的页面
2019-04-26
6重常用的排序算法代码
2019-04-26
VUE CLI 4.x v-for 图片不显示解决方法
2019-04-26
VUE CLI 4.x 打包成APP后白屏解决办法&&打包APP教程
2019-04-26
解决Vue history模式下路由跳转时页面404问题
2019-04-26
Vue项目页面跳转时,窗口上方显示进度条(Vue使用NProgress)
2019-04-26
Vue+axios下载文件
2019-04-26
Element UI table宽度自适应
2019-04-26
Vue引入ECharts图表
2019-04-26
Vue watch监听数据 ECharts异步加载数据
2019-04-26
Vue 3.0引入axios
2019-04-26
网页自动适配 Mac 的 Dark Mode
2019-04-26
The server encountered an unexpected condition that prevented it from fulfilling the request.
2019-04-26
linux安装FastDFS+Nginx
2019-04-26
FastDFS上传文件示例
2019-04-26
Zookeeper集群
2019-04-26