Problems with iterator in a member function in a templated class

Discussion in 'C++' started by William Payne, Aug 31, 2004.

  1. Consider this (templated) class member function:

    template<typename Type>
    void CircularContainer<Type>::insert(const Type& s)
    {
    vector<Type>::iterator itr = find(m_elements.begin(), m_elements.end(),
    s);
    // snip
    }

    m_elements is: std::vector<Type> m_elements; and it's declared in the
    private section of the class CircularContainer. When I try to compile this
    class, it chokes on the iterator - my compiler says:
    circular_container.cpp:13: error: expected `;' before "itr"
    and line 13 is:
    vector<Type>::iterator itr = find(m_elements.begin(), m_elements.end(), s);

    Where is my error? Hope I posted enough code for you to help me....

    / WP
     
    William Payne, Aug 31, 2004
    #1
    1. Advertising

  2. William Payne

    Kai-Uwe Bux Guest

    William Payne wrote:

    > Consider this (templated) class member function:
    >
    > template<typename Type>
    > void CircularContainer<Type>::insert(const Type& s)
    > {
    > vector<Type>::iterator itr = find(m_elements.begin(), m_elements.end(),


    try

    typename vector<Type>::iterator itr = ...


    > s);
    > // snip
    > }
    >
    > m_elements is: std::vector<Type> m_elements; and it's declared in the
    > private section of the class CircularContainer. When I try to compile this
    > class, it chokes on the iterator - my compiler says:
    > circular_container.cpp:13: error: expected `;' before "itr"
    > and line 13 is:
    > vector<Type>::iterator itr = find(m_elements.begin(), m_elements.end(),
    > s);
    >
    > Where is my error? Hope I posted enough code for you to help me....
    >
    > / WP
     
    Kai-Uwe Bux, Aug 31, 2004
    #2
    1. Advertising

  3. "Kai-Uwe Bux" <> wrote in message
    news:ch255n$eqm$...
    > William Payne wrote:
    >
    >> Consider this (templated) class member function:
    >>
    >> template<typename Type>
    >> void CircularContainer<Type>::insert(const Type& s)
    >> {
    >> vector<Type>::iterator itr = find(m_elements.begin(),
    >> m_elements.end(),

    >
    > try
    >
    > typename vector<Type>::iterator itr = ...
    >
    >
    >> s);
    >> // snip
    >> }
    >>
    >> m_elements is: std::vector<Type> m_elements; and it's declared in the
    >> private section of the class CircularContainer. When I try to compile
    >> this
    >> class, it chokes on the iterator - my compiler says:
    >> circular_container.cpp:13: error: expected `;' before "itr"
    >> and line 13 is:
    >> vector<Type>::iterator itr = find(m_elements.begin(), m_elements.end(),
    >> s);
    >>
    >> Where is my error? Hope I posted enough code for you to help me....
    >>
    >> / WP

    >


    Thanks alot, that worked. Silly me had only tried vector<typename
    Type>::iterator...

    Anyway, now I got a few linking errors instead but I think I can solve those
    myself.

    Thanks again!
     
    William Payne, Aug 31, 2004
    #3
  4. "William Payne" <> wrote in message
    news:ch25tb$cg2$...
    >
    > "Kai-Uwe Bux" <> wrote in message
    > news:ch255n$eqm$...
    >> William Payne wrote:
    >>
    >>> Consider this (templated) class member function:
    >>>
    >>> template<typename Type>
    >>> void CircularContainer<Type>::insert(const Type& s)
    >>> {
    >>> vector<Type>::iterator itr = find(m_elements.begin(),
    >>> m_elements.end(),

    >>
    >> try
    >>
    >> typename vector<Type>::iterator itr = ...
    >>
    >>
    >>> s);
    >>> // snip
    >>> }
    >>>
    >>> m_elements is: std::vector<Type> m_elements; and it's declared in the
    >>> private section of the class CircularContainer. When I try to compile
    >>> this
    >>> class, it chokes on the iterator - my compiler says:
    >>> circular_container.cpp:13: error: expected `;' before "itr"
    >>> and line 13 is:
    >>> vector<Type>::iterator itr = find(m_elements.begin(), m_elements.end(),
    >>> s);
    >>>
    >>> Where is my error? Hope I posted enough code for you to help me....
    >>>
    >>> / WP

    >>

    >
    > Thanks alot, that worked. Silly me had only tried vector<typename
    > Type>::iterator...
    >
    > Anyway, now I got a few linking errors instead but I think I can solve
    > those myself.
    >
    > Thanks again!
    >


    Solved the linking errors! Forgot that I had to move my the implementation
    of the member functions to the header.

    / WP
     
    William Payne, Aug 31, 2004
    #4
    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. Jahagirdar Vijayvithal S
    Replies:
    2
    Views:
    448
    Jahagirdar Vijayvithal S
    Aug 7, 2005
  2. Amadeus W. M.
    Replies:
    2
    Views:
    415
    Amadeus W. M.
    Jul 4, 2006
  3. Replies:
    1
    Views:
    320
  4. chhenning
    Replies:
    5
    Views:
    386
    chhenning
    Feb 13, 2008
  5. JPonens
    Replies:
    2
    Views:
    349
    Victor Bazarov
    Mar 21, 2011
Loading...

Share This Page