【发布时间】:2010-05-27 21:53:27
【问题描述】:
我正在尝试使用 TinyXML (c++) 从 xml 文件加载数据。
int height = rootElem->attrib<int>("height", 480);
rootElem 是加载的 xml 文件的根元素。我想从中加载 height 值(整数)。但我有这个东西的包装函数:
template<typename T>
T getValue(const string &key, const string &defaultValue = "")
{
return mRootElement->attrib<T>(key, defaultValue);
}
它适用于字符串:
std::string temp = getValue<std::string>("width");
在获取过程中失败:
int temp = getValue<int>("width");
>no matching function for call to ‘TiXmlElement::attrib(const std::string&, const std::string&)’
UPD:新版代码:
template<typename T>
T getValue(const string &key, const T &defaultValue = T())
{
return mRootElement->attrib<T>(key, defaultValue);
}
【问题讨论】: