473,791 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with map iterator


Help! I am writing an image processing package. For
one constructor, I allow creating an image from a
map of points and color values. The points are
of a "position" class and the colors are just a
vector. It starts thusly:

template <class T>
image<T>::image (map<position<i nt, vector<T >& in_map){

cerr<< "***** ***** ***** ***** ***** *****\n";
cerr<< "making image from map \n";
cerr<< "***** ***** ***** ***** ***** *****\n";

// make an iterator into the input map
map< position<int>, vector<T::itera tor mapit;
mapit = in_map.begin();
.... do stuff with the iterator

}
Oddly, this compiled just fine a month or so ago before I
upgraded my OS from Mandriva 2006 to Mandriva 2007.

Now, however, I get the error:

constructors.cp p: In constructor 'image<T>::imag e(std::map<posi tion<int>, std::vector<T, std::allocator< _CharT, std::less<posit ion<int, std::allocator< std::pair<const position<int>, std::vector<T, std::allocator< _CharT >&)':
constructors.cp p:127: error: expected `;' before 'mapit'
constructors.cp p:128: error: 'mapit' was not declared in this scope

Even more oddly, to me, if I add another iterator, I don't get
an additional error:
template <class T>
image<T>::image (map<position<i nt, vector<T >& in_map){

cerr<< "***** ***** ***** ***** ***** *****\n";
cerr<< "making image from map \n";
cerr<< "***** ***** ***** ***** ***** *****\n";

// make an iterator into the input map
map<char,int>:: iterator testiterator;
map< position<int>, vector<T::itera tor mapit;
mapit = in_map.begin();
.... do stuff with the iterator

}

gives the same error -- it doesn't choke on testiterator.

Configuration:

HP Pavilion zd8000 Pentium4 laptop
Mandriva 2007 linux
gcc version 4.1.1 20060724 (prerelease) (4.1.1-3mdk)
Any pointers would be appreciated!!

Thanks,

billo
Dec 10 '06 #1
5 1999
Bill Oliver wrote:
Help! I am writing an image processing package. For
one constructor, I allow creating an image from a
map of points and color values. The points are
of a "position" class and the colors are just a
vector. It starts thusly:

template <class T>
image<T>::image (map<position<i nt, vector<T >& in_map){

cerr<< "***** ***** ***** ***** ***** *****\n";
cerr<< "making image from map \n";
cerr<< "***** ***** ***** ***** ***** *****\n";

// make an iterator into the input map
map< position<int>, vector<T::itera tor mapit;
replace the line above with:

typename map< position<int>, vector<T::itera tor mapit;
mapit = in_map.begin();
....
Any pointers would be appreciated!!
Types from dependant classes need a "typename" specifier.
Dec 10 '06 #2
In article <12************ *@corp.supernew s.com>,
Bill Oliver <bi***@radix.ne twrote:
>
Help! I am writing an image processing package..

Here's some further data. The error goes away, and
the program runs fine if I replace:

map<position<in t>,vector<T::it erator mapit;

with

map<position<in t>,vector<float ::iterator mapit;
even though T is set to float in the calling routine.
billo
Dec 10 '06 #3
In article <45************ **********@per-qv1-newsreader-01.iinet.net.au >,
Gianni Mariani <gi*******@mari ani.wswrote:
>
Types from dependant classes need a "typename" specifier.


Thank you!!!! That was exactly the problem. Doh.

Now I am wondering why it *used* to work OK.

billo
Dec 10 '06 #4
Bill Oliver wrote:
>
Help! I am writing an image processing package. For
one constructor, I allow creating an image from a
map of points and color values. The points are
of a "position" class and the colors are just a
vector. It starts thusly:

template <class T>
image<T>::image (map<position<i nt, vector<T >& in_map){

cerr<< "***** ***** ***** ***** ***** *****\n";
cerr<< "making image from map \n";
cerr<< "***** ***** ***** ***** ***** *****\n";

// make an iterator into the input map
map< position<int>, vector<T::itera tor mapit;
typename map< position<int>, vector<T::itera tor mapit;
mapit = in_map.begin();
.... do stuff with the iterator

}
Oddly, this compiled just fine a month or so ago before I
upgraded my OS from Mandriva 2006 to Mandriva 2007.

Now, however, I get the error:

constructors.cp p: In constructor 'image<T>::imag e(std::map<posi tion<int>,
std::vector<T, std::allocator< _CharT, std::less<posit ion<int,
std::allocator< std::pair<const position<int>, std::vector<T,
std::allocator< _CharT >&)': constructors.cp p:127: error: expected
`;' before 'mapit' constructors.cp p:128: error: 'mapit' was not declared
in this scope

Even more oddly, to me, if I add another iterator, I don't get
an additional error:
template <class T>
image<T>::image (map<position<i nt, vector<T >& in_map){

cerr<< "***** ***** ***** ***** ***** *****\n";
cerr<< "making image from map \n";
cerr<< "***** ***** ***** ***** ***** *****\n";

// make an iterator into the input map
map<char,int>:: iterator testiterator;
map< position<int>, vector<T::itera tor mapit;
mapit = in_map.begin();
.... do stuff with the iterator

}

gives the same error -- it doesn't choke on testiterator.
You only need the typename keyword for dependent names. Since
map<char,int>:: iterator does not involve the template paramenter T, it is
not a dependent name, hence no "typename" is needed.
Best

Kai-Uwe Bux
Dec 10 '06 #5
Bill Oliver wrote:
In article <45************ **********@per-qv1-newsreader-01.iinet.net.au >,
Gianni Mariani <gi*******@mari ani.wswrote:
>>
Types from dependant classes need a "typename" specifier.



Thank you!!!! That was exactly the problem. Doh.

Now I am wondering why it *used* to work OK.
I bet, you upgraded you g++.
Best

Kai-Uwe Bux

Dec 10 '06 #6

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

Similar topics

45
3048
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
2
2854
by: Rex_chaos | last post by:
Hi all, I am writing my own container and need an iterator. I am hesitating if I should my iterator should inherited from std::iterator or just write my own one. Please give me an idea. BTW, if I write my own one, should I let it defined inside my container(inner class) or just be a complelely independent class. Thanks.
5
2394
by: Rex_chaos | last post by:
Hi there, I am learning template programming and there is a problem about traits. Now consider a container and an iterator. Here is the code // tag for const iterator and non-const iterator struct non_const_iterator_tag {}; struct const_iterator_tag {}; // traits template <typename T,
0
1386
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 indexing was used, I could do something like child = hole * 2 + 1; but since only thing the function accepts are random access Iterators, how do I calculate the Iterator to the child node? template <typename Iterator, typename Functor> void...
7
1813
by: Christian Christmann | last post by:
Hi, in the past I always appreciated your help and hope that you also can help me this time. I've spent many many hours but still can't solve the problem by myself and you are my last hope. I've a program which is using self-written double-linked lists as a data structure. The template list consists of list elements and the list itself linking the list elements.
2
1673
by: Steve R. Hastings | last post by:
While studying iterators and generator expressions, I started wishing I had some tools for processing the values. I wanted to be able to chain together a set of functions, sort of like the "pipelines" you can make with command-line programs. So, I wrote a module called iterwrap.py. You can download it from here: http://home.blarg.net/~steveha/iterwrap.tar.gz
5
1683
nabh4u
by: nabh4u | last post by:
hi, i have a program where every thing is working properly. i have a vector with some values. i use iterators and delete a specific value in the vector. here the loop runs infinitely only for some values. i dont know what is the problem. sample code: vector<int>::iterator Iterator; for( Iterator = vect.cmatch.begin(); Iterator != vect.cmatch.end();Iterator++ ) { if(*Iterator==temp2) vect.cmatch.erase(Iterator);
5
3158
by: ryanoasis | last post by:
Working on a C++ assignment and I cant figure out the problems I am having w/ Templates and Subclasses. I know there are issues with templates and certain compilers so I am not sure what the problem is exactly. I am hoping its an easy overlook. This class is of the linkedLIst, Iterator, and Node modified to use Templates and so that Iterator and Node are subclasses of List
7
1893
by: DJ Dharme | last post by:
Hi, I really like to use stl as much as possible in my code. But I found it really hard to understand by looking into there source code. I have no idea about what iterator traits, heaps and allocators are. So I started to write my own container class to learn templates. I thought about a sorted vector class which have a additional two methods sort and insert sorted. The usage of this class is like this. 1. We can reserve some space and...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.