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);
}