c++ 类函数是模板函数的调用方法

#include <iostream>
using namespace std;
class A {
public:
  template<typename T>  void display(T temp);
  template<typename T>  A(T temp);
};
template<typename T> 
void A::display(T temp)
{
 cout<<temp<<endl;
}
template<typename T> 
A::A(T temp)
{
 cout<<temp<<endl;
}
template <typename T>
void test(T temp)
{
 cout<<temp<<endl;
}
  
void main()
{  test<int>(12);  //普通模板函数,在VS2013下测试,其实加不加后面的<int>都可
  A aa(12); //请注意这一行
  aa.display<int>(15); //成员函数是模板函数 
}

https://www.cnblogs.com/yongdaimi/p/9553098.html

posted @   无左无右  阅读(235)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示