Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problems with iterator in a member function in a templated class

Reply
Thread Tools

Problems with iterator in a member function in a templated class

 
 
William Payne
Guest
Posts: n/a
 
      08-31-2004
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


 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      08-31-2004
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


 
Reply With Quote
 
 
 
 
William Payne
Guest
Posts: n/a
 
      08-31-2004

"Kai-Uwe Bux" <(E-Mail Removed)> wrote in message
news:ch255n$eqm$(E-Mail Removed)...
> 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!


 
Reply With Quote
 
William Payne
Guest
Posts: n/a
 
      08-31-2004

"William Payne" <(E-Mail Removed)> wrote in message
news:ch25tb$cg2$(E-Mail Removed)...
>
> "Kai-Uwe Bux" <(E-Mail Removed)> wrote in message
> news:ch255n$eqm$(E-Mail Removed)...
>> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining templated member function outside templated class chhenning C++ 5 02-13-2008 07:36 PM
Calling templated member of templated object david@sunlightd.com C++ 1 06-22-2007 05:13 PM
templated function as parameter of another templated function Amadeus W. M. C++ 2 07-04-2006 09:59 PM
Problem with member function of a templated class returning a pointer to an object of the same class Jahagirdar Vijayvithal S C++ 2 08-07-2005 10:13 AM
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM



Advertisments