Compiler warning regarding type definition

D

DFP

I am posting the gcc 3.3.2 compiler error and the source lines below
them. Please explain this warning and how to fix it.

crt/crtmap.hpp:17: warning: `std::map<K, D, C,
std::allocator<std::pair<const
_Key, _Tp> > >::iterator' is implicitly a typename
crt/crtmap.hpp:17: warning: implicit typename is deprecated, please see the
documentation for details
crt/crtmap.hpp:18: warning: `std::map<K, D, C,
std::allocator<std::pair<const
_Key, _Tp> > >::const_iterator' is implicitly a typename
crt/crtmap.hpp:18: warning: implicit typename is deprecated, please see the
documentation for details

----------------

Here is the offending code:

template <class K,class D,class C>
class CRTMap
{

private:
mutable std::map<K,D,C> mymap;
mutable CRTMLock MLock;

public:
typedef std::map<K,D,C>::iterator iterator; //// Line 17
typedef std::map<K,D,C>::const_iterator const_iterator; //// Line 18

inline CRTMap(void)
{
}

[...]
 
L

Leor Zolman

I am posting the gcc 3.3.2 compiler error and the source lines below
them. Please explain this warning and how to fix it.

Isn't this in the FAQ yet? :)
crt/crtmap.hpp:17: warning: `std::map<K, D, C,
std::allocator<std::pair<const
_Key, _Tp> > >::iterator' is implicitly a typename
crt/crtmap.hpp:17: warning: implicit typename is deprecated, please see the
documentation for details
crt/crtmap.hpp:18: warning: `std::map<K, D, C,
std::allocator<std::pair<const
_Key, _Tp> > >::const_iterator' is implicitly a typename
crt/crtmap.hpp:18: warning: implicit typename is deprecated, please see the
documentation for details

----------------

Here is the offending code:

template <class K,class D,class C>
class CRTMap
{

private:
mutable std::map<K,D,C> mymap;
mutable CRTMLock MLock;

public:
typedef std::map<K,D,C>::iterator iterator; //// Line 17
typedef typename std::map said:
typedef std::map<K,D,C>::const_iterator const_iterator; //// Line 18
typedef typename std::map<K,D,C>::const_iterator const_iterator;

ISO C++ requires type names (as opposed to other kinds of names) dependent
upon a template parameter to be qualified with the keyword "typename". Some
compilers make do without the 'typename', although the code is not
compliant without it.
-leor
 
P

Pete Becker

DFP said:
typedef std::map<K,D,C>::iterator iterator; //// Line 17
typedef std::map<K,D,C>::const_iterator const_iterator; //// Line 18

"//" is sufficient to mark a comment in C++.

typedef typename std::map<K,D,C>::iterator iterator;
typedef typename std::map<K,D,C>::const_iterator const_iterator;

The rule is that std::map<K,D,C>::iterator is assumed to be the name of
an object unless you say that it's the name of a type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top