By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,407 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,407 IT Pros & Developers. It's quick & easy.

Parameterized Template Parameters

P: n/a
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
Dec 9 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Aaron Carroll wrote:
Consider the following:

#include <map>

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


typename Mymap::iterator iter;

Dec 9 '05 #2

P: n/a

Neelesh Bodas wrote:
Aaron Carroll wrote:
Consider the following:

#include <map>

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


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?)

Dec 9 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.