Problems with iterator in a member function in a templated class

W

William Payne

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
 
K

Kai-Uwe Bux

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


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
 
W

William Payne

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!
 
W

William Payne

William Payne said:
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
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top