STL initialize iterator problem with compiler change

B

brianhray

This works find in Dev Studio and Codewarrior but does not compile
GCC4:

template <class T>
void SerializeVector(RArchive &ar, vector<T>& v)
{
for (vector<T>::iterator i = v.begin(); i != v.end(); i++)
SerializeVar(ar, *i);
}


I get "error: expected `;' before 'i'". Even if I just have
"vector<T>::iterator i ". Why would changing compilers cause this
problem? Am I doing something wrong? How do I fix?

--bhr
 
M

mlimber

This works find in Dev Studio and Codewarrior but does not compile
GCC4:

template <class T>
void SerializeVector(RArchive &ar, vector<T>& v)
{
for (vector<T>::iterator i = v.begin(); i != v.end(); i++)
SerializeVar(ar, *i);
}


I get "error: expected `;' before 'i'". Even if I just have
"vector<T>::iterator i ". Why would changing compilers cause this
problem? Am I doing something wrong? How do I fix?

--bhr

g++4 is the more conformant compiler on this point. Your for-loop
should read:

for ( typename vector<T>::iterator i = v.begin(); i != v.end(); ++i)

For the change in the increment, see

http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.15

Cheers! --M
 
P

Pedro Sousa

mlimber said:
g++4 is the more conformant compiler on this point. Your for-loop
should read:

for ( typename vector<T>::iterator i = v.begin(); i != v.end(); ++i)

Can you say where I can read g++4 information about this topic?

I would like to learn it's behavior about the iterators.

Thanks in advance
Pedro Sousa
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top