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.