设为首页 加入收藏

TOP

56.函数模板(二)
2023-07-23 13:39:16 】 浏览:227
Tags:56.
this->age = age; this->name = name; } public: string name; int age; }; template<class T> void myfunc(T &a, T &b) { if (a > b) { cout << "a>b" << endl; } else { cout << "a<=b" << endl; } } //不建议具体化函数模版,因为没有通用性 //具体化函数模版,注意上面的函数模版要有,才能具体化 template<>void myfunc<Maker>(Maker &a, Maker &b) { cout << "函数模版的具体化" << endl; if (a.age > b.age) { cout << "a>b" << endl; } else { cout << "a<=b" << endl; } } void test02() { Maker m1("aaa", 10); Maker m2("bbb", 20); myfunc(m1, m2); } int main() { test02(); system("pause"); return EXIT_SUCCESS; }

参考资料

参考资料来源于黑马程序员

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇栈——stack的用法 下一篇vector的用法

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目