在模板类中使用字符串作为无类型模板参数

使用字符串做为无类型模板参数时要注意以下几点:

1、 template<class Item_type, const char xml_root_name[]>,中不要使用const char* 等类型。

2、在将模板类实例化时,定义的参数要使用extern 声明。extern const char hostport_root_name[];

3、如果该类是写在“.h”文件里的,不要直接extern const char hostport_root_name[] = “hostport”;,而是在头文件里只声明,在CPP中写上实现,const char hostport_root_name[] =  “hostport”;

原文地址:https://www.cnblogs.com/k1988/p/2165660.html