0

I was writing wrapper methods for Boost unordered map container. In boost Unordered Map there is a method begin(), which returns an iterator to the first element. In my wrapper i trying to write a templatized wrapper. For example

template< class Tkey, class Tvalue>
class CMyUnorderedMap
{
       boost::Unordered_map<TKey,  TValue> m_myMap;
    public:
       boost::unordered_map<TKey,  TValue>::iterator Begin();

};

template< class Tkey, class Tvalue> 
boost::unordered_map<TKey,  TValue>::iterator CMyUnorderedMap< TKey,  TValue >::Begin()
{
    return   m_myMap.begin()
}

While compiling the above code(with template argument) i am getting compilation error in VS 2010 as below.

warningc4346: boost::unordered::unordered_map< TKey, TValue>::iterator : dependent name is not a type.

error C3860 template argument list following class template name must list paramaters in the order used in tempate paramater list

But if i compile the code with out template argument the code complies. for example if a specify like below it works

boost::unordered_map< std::string,  std::string>::iterator Begin();

Will any one help

Ushus
  • 63
  • 1
  • 6

2 Answers2

0

When defining a member function of the class template outside the body of the class template, you need to specify the template details.

For your case, you need to use:

template< class Tkey, class Tvalue> // Missing from your code.
boost::unordered_map<TKey,  TValue>::iterator CMyUnorderedMap< TKey,  TValue >::Begin()
{
    return   m_myMap.begin()
}
R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • @R Sahu i specified class template outside the body of the class template, still there is compilation error – Ushus Apr 23 '16 at 04:56
  • 2
    @Ushus, please lease post a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve), and the compiler error message(s). It's not productive to talk via comments. – R Sahu Apr 23 '16 at 04:57
-1

It worked after i changed the code as below

class CMyUnorderedMap
{

   boost::Unordered_map<TKey,  TValue> m_myMap;
public:
 typename boost::unordered_map<TKey,  TValue>::iterator Begin();

};

template< class Tkey, class Tvalue> 

Added the key word typename in decleration and defenition of the function

typename boost::unordered_map<TKey,  TValue>::iterator CMyUnorderedMap< TKey,  TValue >::Begin()

{

    return   m_myMap.begin()
} 
Alan Stokes
  • 18,815
  • 3
  • 45
  • 64
Ushus
  • 63
  • 1
  • 6