By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

Problems with iterator in a member function in a templated class

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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


Jul 22 '05 #2

P: n/a

"Kai-Uwe Bux" <jk********@gmx.net> wrote in message
news:ch**********@murdoch.acc.Virginia.EDU...
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!
Jul 22 '05 #3

P: n/a

"William Payne" <mi**************@student.liu.se> wrote in message
news:ch**********@news.island.liu.se...

"Kai-Uwe Bux" <jk********@gmx.net> wrote in message
news:ch**********@murdoch.acc.Virginia.EDU...
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
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.