Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #13490
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Iterator in a template |
| Date | 2012-01-18 22:36 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <jf8dlo$k79$1@dont-email.me> (permalink) |
| References | <hvjku8-rs3.ln1@darner.ixazon.lan> |
On 1/18/2012 8:49 PM, Pierre Abbat wrote:
> I've used map iterators before; this is my first time making a template.
> hvec (hexagonal vector) is an integral (in the mathematical sense) type
> representing a point in a hexagonal lattice. A harray is an array
> subscripted by an hvec. Currently I use only bytes as the elements, but I
> will need to store larger things in harrays, so I made it a template. I
> wrote this code to clear all elements in the harray:
>
> template<typename T> class harray
> {map<hvec,T *> index;
> public:
> T& operator[](hvec i);
> void clear();
> };
>
> template<typename T> T& harray<T>::operator[](hvec i)
> {hvec q,r;
> q=i/PAGEMOD;
> r=i%PAGEMOD;
> if (!index[q])
> index[q]=(T*)calloc(PAGESIZE,sizeof(T));
> return index[q][r.pageinx()];
> }
>
> template<typename T> void harray<T>::clear()
> {map<hvec,T *>::iterator i; // line 78
> for (i=index.start();i!=index.end();i++)
> {free(i->second);
> i->second=NULL;
> }
> }
>
> When I try to compile it, I get this error:
>
> In file included from /home/phma/hexcode/hexcode.cpp:5:
> /home/phma/hexcode/hvec.h: In member function 'void harray<T>::clear()':
> /home/phma/hexcode/hvec.h:78: error: expected ';' before 'i'
> /home/phma/hexcode/hvec.h:79: error: 'i' was not declared in this scope
>
> How can I fix it?
hmap<>::iterator is a dependent type. use
"typename map<hvec, T*>::iterator"
I believe this is in the FAQ
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Iterator in a template Pierre Abbat <phma@phma.optus.nu> - 2012-01-19 04:49 +0000
Re: Iterator in a template red floyd <no.spam.here@its.invalid> - 2012-01-18 22:36 -0800
Re: Iterator in a template Pierre Abbat <phma@phma.optus.nu> - 2012-01-19 13:05 +0000
Re: Iterator in a template "MikeWhy" <boat042-nospam@yahoo.com> - 2012-01-19 05:44 -0600
Re: Iterator in a template SG <s.gesemann@gmail.com> - 2012-01-19 06:08 -0800
csiph-web