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); //成员函数是模板函数 
}

(1) 要注意的 地方是 函数的实现和申明要写在同一个文件里面,也是说如果类的申明是在 **.h文件里面,那么函数的实现也要在同一个**.h文件里面。