我是靠谱客的博主 精明康乃馨,这篇文章主要介绍在模板类中使用字符串作为无类型模板参数,现在分享给大家,希望可以做个参考。

 

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”;

转载于:https://www.cnblogs.com/k1988/archive/2010/05/11/2165660.html

最后

以上就是精明康乃馨最近收集整理的关于在模板类中使用字符串作为无类型模板参数的全部内容,更多相关在模板类中使用字符串作为无类型模板参数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部