473,404 Members | 2,137 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,404 software developers and data experts.

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<int, 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::iterator 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.cpp: In constructor 'image<T>::image(std::map<position<int>, std::vector<T, std::allocator<_CharT, std::less<position<int, std::allocator<std::pair<const position<int>, std::vector<T, std::allocator<_CharT >&)':
constructors.cpp:127: error: expected `;' before 'mapit'
constructors.cpp: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<int, 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::iterator 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 1978
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<int, 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::iterator mapit;
replace the line above with:

typename map< position<int>, vector<T::iterator 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.supernews.com>,
Bill Oliver <bi***@radix.netwrote:
>
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<int>,vector<T::iterator mapit;

with

map<position<int>,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*******@mariani.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<int, 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::iterator mapit;
typename map< position<int>, vector<T::iterator 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.cpp: In constructor 'image<T>::image(std::map<position<int>,
std::vector<T, std::allocator<_CharT, std::less<position<int,
std::allocator<std::pair<const position<int>, std::vector<T,
std::allocator<_CharT >&)': constructors.cpp:127: error: expected
`;' before 'mapit' constructors.cpp: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<int, 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::iterator 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*******@mariani.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
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
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,...
5
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...
0
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...
7
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. ...
2
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...
5
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...
5
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...
7
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.