在模板类中使用字符串作为无类型模板参数
2010-05-11 14:15
381 查看
template<class Item_type, const char xml_root_name[]> class CConfigItemList{ public: CConfigItemList(){ m_xml_root_name = xml_root_name; } private: string m_xml_root_name; } extern const char hostport_root_name[]; typedef CConfigItemList<string,hostport_root_name> HostPortList_t;
使用字符串做为无类型模板参数时要注意以下几点:
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”;
相关文章推荐
- 在模板类中使用字符串作为无类型模板参数
- 学习C++模板---模板类作为基类,使用参数类
- 类模板,多种类型的类模板,自定义类模板,类模板的默认类型,数组的模板实现,友元和类模板,友元函数,类模板与静态变量,类模板与普通类之间互相继承,类模板作为模板参数,类嵌套,类模板嵌套,类包装器
- 字符串使用&&引用对象作为函数参数
- 使用字符串作为函数模板的实参
- oracle Array类型作为参数传入函数(存储过程) 大字符串参数解决方案
- 非类型模板参数与 非类型类模板参数的使用
- 使用C++11变长参数模板 处理任意长度、类型之参数
- C++中将字符串作为参数传递,应采用什么类型变量
- C++ - 非类型模板参数(nontype template parameters) 使用 及 代码
- 非类型模板参数限制——不可以使用内部链接对象
- C++11可变数量模板参数可变类型模板参数并使用lamada函数调用使用范例
- OC中switch使用字符串作为参数
- python元组类型的变量以及字符串类型的变量作为参数进行传值
- 如何根据User Agent参数字符串判断客户端使用的是什么浏览器的版本及类型
- Linux下使用xargs得到字符串作为参数进行输出、awk得到字符串作为参数进行输出
- C++ - 非类型模板参数(nontype template parameters) 使用 及 代码
- C++基础——使用字符串作为函数模板的实参
- C++ - 非类型模板参数(nontype template parameters) 使用 及 代码
- 浮点数类型计算问题,bigDecimal对象构造函数尽量使用字符串参数