why warning ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <list>
typedef unsigned long u32;

template<typename T>
class exList : public std::list<T>
{
	public:
		 typedef std::list<T>::iterator Iterator;
		 Iterator operator [](u32);	
};

template<typename T>
exList<T>::Iterator exList<T>::operator [](u32 index)
{
   u32 position = 0;
   for(Iterator  cp_iterator = begin(); cp_iterator != end(); ++cp_iterator, ++position)
     if(position  == index) return cp_iterator;
		
	
					
   return (size()) ? --end() : end();
}


//My compiler give me this:
/*# ---------------------
#      13: exList<T>::Iterator exList<T>::operator [](u32 index)
# Warning:                     ^^^^^^
#   'typename' is missing in template argument dependent qualified type*/



I didn't understand, why my compiler don't like that?

I'm not sure, but try changing the typedef to:

 
typedef typename std::list<T>::iterator Iterator;
>I'm not sure, but try changing the typedef to...

I tryed and same outcome.
I managed to compile it without warnings on g++. I had to add the typename keyword to both the typedef and the return value. I also had to explicitly specify this as the receiver of all functions called in operator[]. I haven't really figured out why, but it's certainly ugly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <list>
typedef unsigned long u32;

template<typename T>
class exList : public std::list<T>
{
	public:
		 typedef typename std::list<T>::iterator Iterator;
		 Iterator operator [](u32);	
};

template<typename T>
typename exList<T>::Iterator exList<T>::operator [](u32 index)
{
   u32 position = 0;
   for(Iterator cp_iterator = this->begin(); cp_iterator != this->end(); ++cp_iterator, ++position)
     if(position  == index) return cp_iterator;
		
	
					
   return (this->size()) ? --this->end() : this->end();
}


I think you are better off not using inheritance. If you look at standard templates like stack and queue, that builds on another container type, you see that they didn't use inheritance. It's probably a good reason for that. Maybe you should declare your template something like this:

1
2
3
4
5
template< typename T, class Container = std::list<T> > 
class exList {
    Container  c;
    // ...
};
It's look like a composition and in this case I need to declare and define methods like push_back, push_front, insert, size, clear... again, but any way thanks a lot.
Topic archived. No new replies allowed.