类模板成员函数类外实现

#include <iostream>

template<class typeName>
class Person
{
public:
   Person(typeName name);
   void show();

protected:
   typeName m_name;
};

template<class typeName>
Person<typeName>::Person(typeName name):
   m_name(name)
{
   
}

template<class typeName>
void Person<typeName>::show()
{
   std::cout << "name " << m_name << std::endl;
}

int main()
{
   Person<std::string> p("furong");
   p.show();

   return 0;
}
posted @ 2022-07-21 08:19  thomas_blog  阅读(33)  评论(0编辑  收藏  举报