This question already has an answer here:
i was making a config file parser and i had a error. i followed this website to make it: http://www.dreamincode.net/forums/topic/183191-create-a-simple-configuration-file-parser/
i tried to separate it into a header and cpp file:
header:
class ConfigFile {
private: //vars and stuffs here
public:
template <typename ValueType>
ValueType getValueOfKey(const std::string &key, ValueType const &defaultValue) const;
};
cpp:
template <typename ValueType>
ValueType ConfigFile::getValueOfKey(const std::string &key, ValueType const &defaultValue = ValueType()) const
{ if (!keyExists(key)) return defaultValue;
return Convert::string_to_T<ValueType>(contents.find(key)->second);
}
another cpp that executes it:
bool configstuff() {
ConfigFile cfg("spotify.ini");
// cfg.keyExists("car");
string someValue = cfg.getValueOfKey<string>("mykey", "Unknown");
// string carValue = cfg.getValueOfKey<string>("car");
// MessageBox(0, (LPCWSTR)someValue.c_str(), L"Msg title", MB_OK | MB_ICONQUESTION);
}
the function declaration and definition are ok. the line "ConfigFile cfg("spotify.ini");" is ok too (i commented other lines out to test it).
thats mean the error is in cfg.getValueOfKey<string>("mykey", "Unknown");
i got the error
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl ConfigFile::getValueOfKey<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (??$getValueOfKey@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@ConfigFile@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV12@0@Z)
i have no idea where the problem is.
i have tried fixing it for more than 4 hours but stil couldnt find the solution. please help. thanks!
Aucun commentaire:
Enregistrer un commentaire