The function getdata() works fine without the template but when I put the template in I get this error
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: char const * __thiscall json_map::getdata<char const *>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??$getdata@PBD@json_map@@QAEPBDV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main banking
struct declaration in header file:
struct json_map {
std::map<std::string, std::any> data;
template<typename A>
A getdata(std::string key);
};
function declaration:
template<typename A>
A json_map::getdata(std::string key)
{
return std::any_cast<A>(data[key]);
}
function use:
map1.getdata<std::string>("walid");