Connecting Tech Pros Worldwide Forums | Help | Site Map

STL initialize iterator problem with compiler change

brianhray@gmail.com
Guest
 
Posts: n/a
#1: Jun 5 '06

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


mlimber
Guest
 
Posts: n/a
#2: Jun 5 '06

re: STL initialize iterator problem with compiler change


brianhray@gmail.com wrote:[color=blue]
> 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[/color]

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-lit...html#faq-13.15

Cheers! --M

Pedro Sousa
Guest
 
Posts: n/a
#3: Jun 13 '06

re: STL initialize iterator problem with compiler change


mlimber wrote:[color=blue]
> brianhray@gmail.com wrote:[color=green]
>> 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[/color]
>
> 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)[/color]

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
[color=blue]
>
> For the change in the increment, see
>
> http://www.parashift.com/c++-faq-lit...html#faq-13.15
>
> Cheers! --M
>[/color]

--
Posted via a free Usenet account from http://www.teranews.com

mlimber
Guest
 
Posts: n/a
#4: Jun 13 '06

re: STL initialize iterator problem with compiler change



Pedro Sousa wrote:[color=blue]
> mlimber wrote:[color=green]
> > brianhray@gmail.com wrote:[color=darkred]
> >> 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[/color]
> >
> > 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)[/color]
>
> Can you say where I can read g++4 information about this topic?
>
> I would like to learn it's behavior about the iterators.[/color]

You should ask in a g++ newsgroup, two of which are listed in this FAQ:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M

Roland Pibinger
Guest
 
Posts: n/a
#5: Jun 13 '06

re: STL initialize iterator problem with compiler change


On Tue, 13 Jun 2006 19:25:21 +0000, Pedro Sousa <pasousa@inbox.com>
wrote:[color=blue]
>mlimber wrote:[color=green]
>> 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)[/color]
>
>Can you say where I can read g++4 information about this topic?
>I would like to learn it's behavior about the iterators.[/color]

http://womble.decadentplace.org.uk/c...disambiguation
Closed Thread


Similar C / C++ bytes