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 @ 2022-02-11 14:14  无左无右  阅读(224)  评论(0编辑  收藏  举报