Maps, Iterators and Templated Classes

J

jschon

Hi,
I'm trying to write a thread safe hash map class. Basically I have put
some packaging around the STL map class to ensure thread safe access.
The container is a templated class.

I'm having trouble with a line of code:

map<string, T*>::iterator all_it = all.begin();

when i compile it i get the error:
objectcontainer.cpp:127: error: expected `;' before "all_it"

however if i change the line of code to:
map<string, int*>::iterator all_it = all.begin();

the error completely goes away.

the function this code snippet is in is defined as such:
template <class T>
void ObjectContainer<T>::copy(const ObjectContainer<T>& o){
---body---
}


if anybody knows what I am doing incorrectly I would be very much
obliged if you could let me know, or give me some tips. I'm VERY stuck
here.

Thanks!,
Jake
 
V

Victor Bazarov

I'm trying to write a thread safe hash map class. Basically I have
put some packaging around the STL map class to ensure thread safe
access. The container is a templated class.

I'm having trouble with a line of code:

map<string, T*>::iterator all_it = all.begin();

when i compile it i get the error:
objectcontainer.cpp:127: error: expected `;' before "all_it"

however if i change the line of code to:
map<string, int*>::iterator all_it = all.begin();

the error completely goes away.

the function this code snippet is in is defined as such:
template <class T>
void ObjectContainer<T>::copy(const ObjectContainer<T>& o){
---body---
}


if anybody knows what I am doing incorrectly I would be very much
obliged if you could let me know, or give me some tips. I'm VERY
stuck here.

This is covered in the FAQ. See section 35, at the end. Or search for
"dependent name". What you need is to tell the compiler that what you
are using is a type by prepending your declaration with 'typename'.

V
 
J

jschon

Perfect. I didn't see the FAQ, i'm new to Bulletin Board questions.
I'll look into that next time.

Thanks for the help, that worked perfectly. I have never heard of that
rule before

Thanks again!
-jake-
 
T

Thorsten Kiefer

I had the same problem once, and it took me about an hour find the
solution ;)
 

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

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top