Help with map iterator

B

Bill Oliver

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
 
G

Gianni Mariani

Bill said:
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:

mapit = in_map.begin(); ....
Any pointers would be appreciated!!

Types from dependant classes need a "typename" specifier.
 
B

Bill Oliver

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
 
B

Bill Oliver

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
 
K

Kai-Uwe Bux

Bill said:
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.

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
 
K

Kai-Uwe Bux

Bill said:
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
 

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

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top