Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: STL container iterator not available within template?

Reply
Thread Tools

Re: STL container iterator not available within template?

 
 
Saeed Amrollahi
Guest
Posts: n/a
 
      06-18-2009
On Jun 18, 1:29*pm, "Sam" <(E-Mail Removed)> wrote:
> Hi there,
>
> Here's the problem I just encountered. For the following code
>
> #include <set>
>
> template <class T>
> class A
> {
> * * std::set<T*>::iterator a;
>
> };
>
> int main()
> {
>
> }
>
> g++ generated this error:
> t.cpp:6: error: expected `;' before "a"
>
> Anyone can help? Thanks in advance.
>
> Best Regards,
> Sam


Hi Sam

use typename:
typename std::set<T*>::iterator a;

Regards,
-- Saeed Amrollahi
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      06-18-2009
Sam wrote:
>> Hi Sam
>>
>> use typename:
>> typename std::set<T*>::iterator a;
>>
>> Regards,
>> -- Saeed Amrollahi

>
> Thank you very much Saeed! Problem solved!


Basically the idea is that since T is a template parameter type, the
std::set<T*>::iterator type becomes dependent of T. The standard
requires that whether that "iterator" is a type or not must be
disambiguated with the typename keyword. Without the typename keyword
the compiler assumes that "iterator" is actually a member of
std::set<T*>, rather than a nested type.

(Technically speaking, the compiler could *assume* it's a type because
it's being used like a type, and in fact older compilers did just that.
However, the standard requires the disambiguation.)
 
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
Custom iterator for STL-style container gallows C++ 3 03-05-2007 04:05 PM
STL inherit from container<T>::iterator Christoph Heindl C++ 2 04-04-2006 06:41 AM
Copy elements from one STL container to another STL container Marko.Cain.23@gmail.com C++ 4 02-16-2006 05:03 PM
item callback on container or why STL does not have pointer to iterator conversion open? forester C++ 16 08-25-2005 03:37 PM
std::container::iterator vs std::container::pointer Vivi Orunitia C++ 11 02-04-2004 08:09 AM



Advertisments