1
votes

I was writing wrapper methods for Boost unordered map container.In my wrapper i was trying to write a templatized wrapper.For the below mentioned code i am getting compilation error in VS 2010 as below. Ant one help pls.

template< class Tkey, class Tvalue>
class CHashMap
{ 
  unordered_map<Tkey, Tvalue> m_HashMap;
};

template< class Tkey, class Tvalue>
unordered_map::iterator CHashMap<Tkey, Tvalue>::SetAt(Tkey, Tvalue)
{
   m_HashMap.insert(std::make_pair(Tkey, Tvalue));
}

void main()
{
  CHashMap<std::string, std::string> m_mymap;
  m_mymap.SetAt("1","Some value");
}

Error C2275:'Tkey' illegal use of this type as an expression.

Error C2275:'TValue' illegal use of this type as an expression.

Also i would like to know one moer thing,

Is it better to use template as arguments to unordered_map or boost::any.

1

1 Answers

1
votes

You're missing the names of the arguments - you're currently just using the types:

template <class Tkey, class Tvalue>
unordered_map::iterator CHashMap<Tkey, Tvalue>::SetAt(Tkey key, Tvalue value)
//                                                        ^^^^        ^^^^^^
{
   m_HashMap.insert(std::make_pair(key, value));
//                                 ^^^  ^^^^^
}