typename conundrum
Kris Thielemans
kris.thielemans@csc.mrc.ac.uk
Wed May 14 00:27:00 GMT 2003
Hi,
First of all: sorry to post this question! I know there have been
various emails on this topic before, and even bugs submitted and
resolved. However, the status of all these reports/bugs is unclear to
me... Sorry again.
I have trouble with modifying my code to get rid of the 'deprecated
feature' warning related to the typename keyword in C++. I have tested
this in 3.1 and 3.2 (sorry, nothing more recent yet). Here is my code,
with comments flagging where the warning appears.
-----------------------------------------
template <class T>
class V
{
public:
typedef T* iterator;
iterator begin();
};
template <class T>
class derived: public V<T>
{
void f();
};
template <class T>
void derived<T>::f()
{
// compiler warning in next line:
// `typename derived<T>::iterator' is implicitly a typename
iterator iter = begin();
// next line works, but is awkward
typename derived<T>::iterator iter1 = begin();
// compiler error in next line:
// parse error before `=' token
typename iterator iter2 = begin();
}
template derived<int>;
-----------------------------------------
Obviously, my 3rd attempt ("typename iterator") was pretty desperate. It
doesn't even compile with gcc 2.95.2 or 3.0.
I understand why the 2nd attempt ("typename derived<T>::iterator") does
work without warnings. It is the standard thing to do with templated
arguments (e.g. "typename T::iterator").
The main questions are thus:
- why does the 1st attempt generate a warning? The compiler can easily
figure out it's a type.
- what does the C++ standard has to say about this? (Naively I would
think that if the 1st isn't correct, than the 3rd should be)
- how do I fix the 1st attempt without having to resort to the ugly 2nd
attempt?
In case my 1st attempt is legal C++, and this issue has been addressed
in more recent releases of gcc, I would very much appreciate a version
number where this has been fixed.
Many thanks
Kris Thielemans
Imaging Research Solutions Ltd
More information about the Gcc
mailing list