C++类中的成员函数和构造函数为模板函数时的调用方法
2021-07-11 00:06
阅读:752
标签:类型 pen end include mes color 调用 play 测试
所谓模板函数其实就是建立一个通用函数,这个通用函数的形参类型不具体指定,用一个虚拟类型来代表,这个通用函数就被称为函数模板。
例:
#includeusing namespace std; class A { public: template void display(T temp); template A(T temp); };
templatevoid A::display(T temp) { coutendl; }
templateA::A(T temp) { coutendl; }
templatevoid test(T temp) { coutendl; } void main() {
testint>(12); //普通模板函数,在VS2013下测试,其实加不加后面的都可 A aa(12); //请注意这一行 aa.displayint>(15); //成员函数是模板函数 }
C++类中的成员函数和构造函数为模板函数时的调用方法
标签:类型 pen end include mes color 调用 play 测试
原文地址:https://www.cnblogs.com/yongdaimi/p/9553098.html
下一篇:启动jar命令
评论
亲,登录后才可以留言!