Defining iterators

D

Denis Remezov

Deke said:
I upgraded to gcc 3.4 and ran into the problem below. I don't understand
it and need to fix this quickly. Any resolutions in changing to code
will be appreciated. I will research this later this week as time allows
but a quick resolution with code example will help a great deal.

Thanks

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

crt/crtmap.hpp:17: error: type `std::map<K, D, C,
std::allocator<std::pair<const _Key, _Tp> > >
' is not derived from type `CRTMap<K, D, C>'

crt/crtmap.hpp:17: error: ISO C++ forbids declaration of `iterator' with
no type

crt/crtmap.hpp:17: error: expected `;' before "iterator"

crt/crtmap.hpp:18: error: type `std::map<K, D, C,
std::allocator<std::pair<const _Key, _Tp> > >
' is not derived from type `CRTMap<K, D, C>'

crt/crtmap.hpp:18: error: ISO C++ forbids declaration of
`const_iterator' with no type

crt/crtmap.hpp:18: error: expected `;' before "const_iterator"

------

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


It's become quite a FAQ that is not yet in The FAQ.

Must use typename with dependent type names:
typedef typename std::map<K,D,C>::iterator iterator; // line 17
typedef typename std::map<K,D,C>::const_iterator const_iterator; // line 18

(the older compiler versions were slacking on the standard)

Denis
 
D

Deke

I upgraded to gcc 3.4 and ran into the problem below. I don't understand
it and need to fix this quickly. Any resolutions in changing to code
will be appreciated. I will research this later this week as time allows
but a quick resolution with code example will help a great deal.

Thanks

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

crt/crtmap.hpp:17: error: type `std::map<K, D, C,
std::allocator<std::pair<const _Key, _Tp> > >
' is not derived from type `CRTMap<K, D, C>'

crt/crtmap.hpp:17: error: ISO C++ forbids declaration of `iterator' with
no type

crt/crtmap.hpp:17: error: expected `;' before "iterator"

crt/crtmap.hpp:18: error: type `std::map<K, D, C,
std::allocator<std::pair<const _Key, _Tp> > >
' is not derived from type `CRTMap<K, D, C>'

crt/crtmap.hpp:18: error: ISO C++ forbids declaration of
`const_iterator' with no type

crt/crtmap.hpp:18: error: expected `;' before "const_iterator"

------

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
 
P

P.J. Plauger

It's become quite a FAQ that is not yet in The FAQ.

Must use typename with dependent type names:
typedef typename std::map<K,D,C>::iterator iterator; // line 17
typedef typename std::map<K,D,C>::const_iterator const_iterator; // line 18

(the older compiler versions were slacking on the standard)

The standard *did* change underfoot, you know.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 

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