On Jul 19, 10:06 pm, algatt <alang...@gmail.com> wrote:
> template<class K, class T, class W>
> class AMI_cache_manager_static: public AMI_cache_manager_base {
> private:
> map<K,T> data_;
> size_t current_size;
> W writeout_;
> public:
> AMI_cache_manager_static(size_t capacity) :
> AMI_cache_manager_base(capacity, 0), writeout_() {
> current_size = 0;
> }
> ~AMI_cache_manager_static(){
> map<K,T>::iterator it;
You need to change this line to:
typename map<K,T>::iterator it;
> it = data_.begin();
> while (it != data_.end()) {
> writeout_(it->second);
> it++;
> }
> }
> I have the above code, but where there is the
> map<K,T>::iterator it; it gives me an error message that a ;
> must be placed before it.
The error message sounds a bit strange, but you definitly need
the typename.
> If I change map<K,T>::iterator it; to map<string,string>::iterator it;
> it works,
That's because the compiler knows that map<string,
string>::iterator is a type. For map<K,T>::iterator, it can't
know until it knows the types K and T. So you have to tell it.
The basic idea is that the compiler should be able to parse a
template definition when it sees it, in order to find obvious
errors. The problem is that the grammar of C++ isn't context
independent, and to part it, the compiler needs to know which
symbols name types. Since it can't possibly know in the above
case (there could be a specialization of map for the actual K
and T), you have to tell it. And if you lie, it's undefined
behavior. (Cruel world, isn't it.)
--
James Kanze (GABI Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
|