C++类模板基本语法

#include <iostream>

template<class typeName, class typeAge>
class Person
{
public:
   Person(typeName name, typeAge age):
   name(name),
   age(age)
   {}

   void show()
   {
      std::cout << "name " << name << std::endl;
      std::cout << "age " << age << std::endl;
   }

protected:
   typeName name;
   typeAge age;
};

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

   return 0;
}
$ ./a.out      
name furong
age 10
posted @ 2022-07-15 14:00  thomas_blog  阅读(14)  评论(0编辑  收藏  举报