Parameterized Template Parameters

A

Aaron Carroll

Consider the following:

#include <map>

template <class T>
void f()
{
typedef std::map<T, int> Mymap;
Mymap::iterator iter;
}

Compiling with both GCC and Comeau gives an error along the lines of
`expected a ";" before "iter".' The same code with the map parameter
T replaced with a concrete type compiles just fine. Instantiating a
"Mymap" seems to work.

Why can I create a "Mymap" object, but not a "Mymap::iterator" object?

Cheers,
-- Aaron
 
N

Neelesh Bodas

Aaron said:
Consider the following:

#include <map>

template <class T>
void f()
{
typedef std::map<T, int> Mymap;
Mymap::iterator iter;

typename Mymap::iterator iter;
 
E

Earl Purple

Neelesh said:
typename Mymap::iterator iter;

The compilers are correct to reject the code but it would be nice if
they could identify the error and give an appropriate message.
(Something compiler vendors could work on perhaps?)
 

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
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top