我正在尝试使用 TinyXML (c++) 从 xml 文件加载数据。
int height = rootElem->attrib<int>("height", 480);
rootElem是加载的 xml 文件的根元素。我想从中加载高度值(整数)。但我有这个东西的包装函数:
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);
}