Hi,
I have a template map and want to use the iterator. But the compile
failed. Is there any restriction on the (const) iterator for template
type?
Sample code:
template <typename T>
void Foo(const std::map<std::string, std::vector<T &data) {
const std::map<std::string, std::vector<T::const_iterator it =
data.begin();
// ...
}
Thanks,
xu@la 2 1109
Hi,
xu@la a écrit :
template <typename T>
void Foo(const std::map<std::string, std::vector<T &data) {
const std::map<std::string, std::vector<T::const_iterator it =
data.begin();
// ...
}
const typename std::map<std::string, std::vector<T::const_iterator it
^^^^^^^^
The 'problem' is that you are in a template, trying to invoke a
dependent name (your const_iterator depends on T), so you must help the
compiler, and tell it it is a type.
I hope it helps,
--
Vincent Jacques
Thanks! It works.
Jinjun
On May 21, 12:37*pm, Vincent Jacques <newsgr...@vincent-jacques.net>
wrote:
Hi,
xu@la a écrit :
template <typename T>
void Foo(const std::map<std::string, std::vector<T &data) {
* const std::map<std::string, std::vector<T::const_iterator it =
data.begin();
* // ...
}
const typename std::map<std::string, std::vector<T::const_iterator it
* * * *^^^^^^^^
The 'problem' is that you are in a template, trying to invoke a
dependent name (your const_iterator depends on T), so you must help the
compiler, and tell it it is a type.
I hope it helps,
--
Vincent Jacques
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: CoolPint |
last post by:
I am trying to write a generic heapsort (of course as a self-exercise)
with Iterator interface: something like blow....
But I got into trouble finding out the Iterator to the Child node. If...
|
by: Michael Klatt |
last post by:
I am trying to write an iterator for a std::set that allows the
iterator target to be modified. Here is some relvant code:
template <class Set> // Set is an instance of std::set<>
class...
|
by: Ken Cecka |
last post by:
This is a contrived example to demonstrate a syntax problem I'm struggling
with:
#include <vector>
template <typename T>
class Class
{
};
|
by: nick |
last post by:
Hi,
I need to manage a "layered" collection of objects, where each layer
grows independently, e.g,
o--+--+--+--+--+ 1st layer
|
o 2nd layer (empty)
|
o--+--+--+ 3rd...
|
by: Dan Tsafrir |
last post by:
is the following code standard? (cleanly compiles under g++-4.0.2):
struct Asc { bool operator()(int a, int b) {return a < b;} };
struct Des { bool operator()(int a, int b) {return b > a;} };...
|
by: chriscorbell |
last post by:
I'm curious about what appears to be a restriction on using an STL
container inside a user-defined template, esp. using an iterator to
such a container. It's not clear to me if this is a general...
|
by: mailforpr |
last post by:
Hi.
Let me introduce an iterator to you, the so-called "Abstract Iterator"
I developed the other day.
I actually have no idea if there's another "Abstract Iterator" out
there, as I have never...
|
by: Axel Gallus |
last post by:
I built a container (without a template), an iterator as a nested class and
a "find"-method:
iterator has a friend relationship with Hash_Map and vice versa.
class Hash_Map
{
iterator...
|
by: mkborregaard |
last post by:
Hi,
I have the weirdest problem, and I can not see what is going wrong.
I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very...
|
by: pnayak |
last post by:
Hi,
I am trying to implement an iterator to a List class. The code is included below. I get the following compiler error. At the point where I use a class that is defined inside a template...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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...
| |