STL initialize iterator problem with compiler change

Discussion in 'C++' started by brianhray@gmail.com, Jun 5, 2006.

  1. Guest

    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
    , Jun 5, 2006
    #1
    1. Advertising

  2. mlimber Guest

    wrote:
    > 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
    mlimber, Jun 5, 2006
    #2
    1. Advertising

  3. mlimber Guest

    Pedro Sousa wrote:
    > mlimber wrote:
    > > wrote:
    > >> 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)

    >
    > Can you say where I can read g++4 information about this topic?
    >
    > I would like to learn it's behavior about the iterators.


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

    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.9

    Cheers! --M
    mlimber, Jun 13, 2006
    #3
  4. Pedro Sousa Guest

    mlimber wrote:
    > wrote:
    >> 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)


    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

    >
    > For the change in the increment, see
    >
    > http://www.parashift.com/c -faq-lite/operator-overloading.html#faq-13.15
    >
    > Cheers! --M
    >


    --
    Posted via a free Usenet account from http://www.teranews.com
    Pedro Sousa, Jun 13, 2006
    #4
  5. On Tue, 13 Jun 2006 19:25:21 +0000, Pedro Sousa <>
    wrote:
    >mlimber wrote:
    >> 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.


    http://womble.decadentplace.org.uk/c /template-faq.html#disambiguation
    Roland Pibinger, Jun 13, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    15
    Views:
    570
    Daniel T.
    Nov 29, 2006
  2. thinktwice
    Replies:
    4
    Views:
    2,781
    James Kanze
    Jul 2, 2008
  3. Replies:
    1
    Views:
    1,104
    Neelesh
    May 19, 2009
  4. Rune Allnor
    Replies:
    2
    Views:
    2,013
    Richard Herring
    Feb 1, 2010
  5. Jim Anderson

    problem with iterator (map iterator)

    Jim Anderson, Jan 10, 2014, in forum: C++
    Replies:
    3
    Views:
    108
    Luca Risolia
    Jan 13, 2014
Loading...

Share This Page