473,382 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Maps, Iterators and Templated Classes

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

Jul 28 '06 #1
4 1259
js****@umich.edu wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 28 '06 #2
js****@umich.edu wrote:
I'm having trouble with a line of code:

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

Jul 28 '06 #3
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-

Jul 28 '06 #4
I had the same problem once, and it took me about an hour find the
solution ;)
js****@umich.edu wrote:
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-
Jul 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vlad | last post by:
Hi, I wonder if it's possible to implement something like typedef map<string, T::iterator> T; i.e. to have a map that will resolve keys to iterators in the map of the same type. In my...
4
by: Merlin | last post by:
Hi, I am a C++ developer and would like to implement container classes for various types of objects. I use MS Visual C++ to compile my code. Nevertheless I like to write code that is independent...
43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
5
by: DrLex | last post by:
This is a really annoying thing to look up in Google because all pages that mention STL maps or vectors will most likely also contain the word "template". So maybe this question has been asked...
6
by: gexarchakos | last post by:
Hi there, Please give me at least a hint... I have a problem implementing a function object with parameters two iterators. That is: A class 'node' produces messages using a routing policy....
2
by: mattjgalloway | last post by:
I'm having some problems with a templated member function of a templated class. Unfortunately I can't replicate it with a simple example so I know something odd must be going on!!! Basically it's...
5
by: pallav | last post by:
I have a map like this: typedef boost::shared_ptr<NodeNodePtr; typedef std::vector<NodePtrNodeVecPtr; typedef std::map<std::string, NodePtrNodeMap; typedef std::map<std:string,...
2
by: domehead100 | last post by:
I have a templated class, CDerived: template <typename TValue, typename TDraw, typename TEdit ...> class CDerived : public CBase { TValue m_Value public: TValue& GetValue() const {
2
card
by: card | last post by:
Hi everyone, I have a question about referencing a nested class contained within a templated class. Of course the best way to show you is by example. Here's my templated classes: #include...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.