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

Cannot make const_iterator of templatized hash_map

P: n/a
In a class templatized by class T, I have the following two lines:

hash_map<string, T> foo;
hash_map<string, T>::const_iterator p;

The first line compiles just fine.
The second line gives the following error: "syntax error before `;'
token"

Any idea how to resolve this error?

Thanks,
Joseph

Aug 2 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Joseph Turian wrote:
In a class templatized by class T, I have the following two lines:

hash_map<string, T> foo;
hash_map<string, T>::const_iterator p;

The first line compiles just fine.
The second line gives the following error: "syntax error before `;'
token"

Any idea how to resolve this error?


For dependent names, if they are types, add 'typename' to help your
compiler:

typename hash_map<string, T>::const_iterator p;

More about it in the FAQ.

V
Aug 2 '05 #2

P: n/a
Okay, I figured it out:
typename hash_map<string, T>::const_iterator p;

However, I have no idea why this works.

Joseph

Aug 2 '05 #3

P: n/a
Joseph Turian wrote:
Okay, I figured it out:
typename hash_map<string, T>::const_iterator p;

However, I have no idea why this works.


Read the FAQ.
Aug 2 '05 #4

P: n/a

Victor Bazarov wrote:
Joseph Turian wrote:
Okay, I figured it out:
typename hash_map<string, T>::const_iterator p;

However, I have no idea why this works.


Read the FAQ.


Victor,

Which question should I be looking for?
I searched the FAQ for typename, however I couldn't find the
appropriate question.

Thanks,

Joseph

Aug 2 '05 #5

P: n/a
Joseph Turian wrote:
Victor Bazarov wrote:
Joseph Turian wrote:
Okay, I figured it out:
typename hash_map<string, T>::const_iterator p;

However, I have no idea why this works.


Read the FAQ.

Victor,

Which question should I be looking for?
I searched the FAQ for typename, however I couldn't find the
appropriate question.


I think section 35 should be of some assistance. Also, read the
archives about "dependent name" or "dependent type".

V
Aug 2 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.