Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #10111
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Defining iterator type through container object type |
| Date | 2011-09-15 10:25 +1200 |
| Message-ID | <9dcnusF786U1@mid.individual.net> (permalink) |
| References | <ygf7h5ayere.fsf@janus.isnogud.escape.de> |
On 09/15/11 09:51 AM, Urs Thuermann wrote:
> Can I define an iterator for an object of a standard container class
> without using the concrete type of that container object?
>
> I tried things like
>
> 1 #include<list>
> 2 void foo(std::list<int> ilist) {
> 3 ilist.iterator it;
> 4 for (it = ilist.begin(); it != ilist.end(); ++it) { *it; }
> 5 }
>
> and
>
> 1 #include<list>
> 2 void foo(std::list<int> ilist) {
> 3 typeof(ilist)::iterator it;
> 4 for (it = ilist.begin(); it != ilist.end(); ++it) { *it; }
> 5 }
>
> For the first code I get
>
> foo.cc:3:11: error: invalid use of 'std::list<int>::iterator'
>
> so at least ilist.iterator seems indeed to be understood as
> std::list<int>::iterator. In the second case I get
>
> foo.cc:3:29: error: expected initializer before 'it'
>
> Is there a way to define the iterator without using std::list<int>::iterator
> explicitly?
Only if your compiler supports the new auto keyword. Otherwise use a
typedef for the parameter type.
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Defining iterator type through container object type Urs Thuermann <urs@isnogud.escape.de> - 2011-09-14 23:51 +0200
Re: Defining iterator type through container object type Ian Collins <ian-news@hotmail.com> - 2011-09-15 10:25 +1200
Re: Defining iterator type through container object type Juha Nieminen <nospam@thanks.invalid> - 2011-09-15 06:49 +0000
Re: Defining iterator type through container object type Marc <marc.glisse@gmail.com> - 2011-09-15 08:03 +0000
Re: Defining iterator type through container object type Urs Thuermann <urs@isnogud.escape.de> - 2011-11-03 14:30 +0100
Re: Defining iterator type through container object type Marc <marc.glisse@gmail.com> - 2011-11-03 18:17 +0000
Re: Defining iterator type through container object type Urs Thuermann <urs@isnogud.escape.de> - 2011-11-04 15:10 +0100
csiph-web