您的位置:首页 > 其它

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

2010-05-11 14:15 525 查看
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”;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐