Skip to content. | Skip to navigation

Personal tools
You are here: Home Programming C, C++ etc. Implicit typename error

Implicit typename error

"Iterator is implicitly a typename ... warning: implicit typename is deprecated"

While compiling some code with gcc (that had previously compiled and run without complaint under CodeWarrior), the following warning was reported:

        SblNumerics.h:334: warning: `typename  std::iterator_traits<_Iterator>::value_type' is implicitly a typename
        SblNumerics.h:334: warning: implicit typename is deprecated, please see the documentation for details

The offending code looks like this:

        template <class Iter>
        inline
        iterator_traits<InputIter>::value_type
        sum (Iter first, Iter last, iterator_traits<Iter>::value_type init)
        {
           ...
        }

or this:

        template <typename X>
        class SimpleMatrix : public std::vector<std::vector<X> >
        {
        public:
           // PUBLIC TYPE INTERFACE
           typedef std::vector<X>              row_type;
           typedef std::vector<row_type>       base_type;
           typedef row_type::size_type         size_type;    // error here ...
           typedef row_type::reference         reference;    // ... and here .... 
           typedef row_type::const_reference   const_reference;   // ... and here   
           ...
        }

The problem here is that when a compiler encounters something like classname::something, it has to decide whether this is a member variable, member function, or name of a type declared inside the class (e.g. a typedef or nested class). In the case of dependent names (ones that depend on a template parameter) this is easy. Often, compilers assume it is a type name - which would be correct in this case. However more recent compilers demand that you resolve this ambiguity. To get this warning to go away the type names must be explicitly identified as such:

        template <class Iter>
        inline
        typename iterator_traits<Iter>::value_type
        sum (Iter first, Iter last, typename iterator_traits<Iter>::value_type init)
        {
           ...
        }

and as such:

        template <typename X>
        class SimpleMatrix : public std::vector<std::vector<X> >
        {
        public:
           // PUBLIC TYPE INTERFACE
           typedef std::vector<X>                       row_type;
           typedef std::vector<row_type>                base_type;
           typedef typename row_type::size_type         size_type;   
           typedef typename row_type::reference         reference;   
           typedef typename row_type::const_reference   const_reference;  
           ...
        }

Document Actions
Visitors
Locations of visitors to this page
Ads
 
Sections