I wrote this little code
std::map<int,template<class T>> map_;
map_.insert(make_pair<int,message>(myMsg.id,myMsg));
but the compiler doesn’t seem to get it and displays as an error
template argument 2 is invalid
and when I tried to correct by doing this
template<class T>
std::map<int,T> map_;
it displays as an error :
expected primary-expression before ‘template’ |
error: expected ‘;’ before ‘template’
I’m not sure about this, but you are trying to declare a variable, and that definition has to be fully defined. Trying to use a template doesn’t fully define the variable.
You can wrap it in a structure if you want to:
Then use it like this: