Getting around typename deprecation

Started by
5 comments, last by Conner McCloud 18 years, 7 months ago
So I have some fairly simple little classes that I've decided to template-ize so that I could switch between doubles and floats easily, and discover that I get hundreds of warnings about implicit typenames being deprecated. I hate the idea of sprinkling my code with 'typename', because it is such a useless tag [to me...I understand that the compiler needs it], so I typedef'd the offending items. That works great, and frankly the code looks cleaner for it with or without the typename issue. The problem is that some of these classes get derived from. Naturally, I want to use the same type names in these classes. However, since the derived class is templated, gcc still bitches about implicit typenames. Extremely annoying. In fact, this is more annoying than before...whereas originally iterators were the prime issue, now the underlying containers whine as well. So far, I've come up with two solutions, both of which require redoing the typedefs within the derived classes. I dislike both of them. Actually, just now it occurs to me that a third solution could involve the preprocessor, but I don't like it much either. So: are there any other ways of letting the compiler know that an explicit typename isn't neccessary? Without --no-deprecated, that is. I often compile without makefiles, and invariably forget to provide compiler options. For reference, here's a snippet of code that illustrates the issue:

template<class T> struct Base
{
    typedef typename std::vector<T> Vector;
    Vector iLikeThisLine;
};

template<class T> struct Derived : Base<T>
{
    Vector iHateThisLine;
};
And the output:
Quote:Emphasis added templates.cpp:12: warning: `typename Derived<T>::Vector' is implicitly a typename templates.cpp:12: warning: implicit typename is deprecated, please see the documentation for details
My favorite solution thus far:

template<class T> struct Derived : Base<T>
{
    typedef typename Base<T>::Vector Vector;
    Vector iNoLongerHateThisLine;
}
Any suggestions would be appreciated. Everything is working great except these annoying warnings. CM
Advertisement
Try just:

using Vector;
Quote:Original post by SiCrane
Try just:

using Vector;

I thought of that. Unfortunately, it is a parse error.
Quote:
templates.cpp:11: parse error before `;' token
templates.cpp:12: warning: `typename Derived<T>::Vector' is implicitly a typename
templates.cpp:12: warning: implicit typename is deprecated, please see the documentation for details

Expanding the line a bit to using Base<T>::Vector removes the parse error but the warning remains, and using typename Base<T>::Vector is a parse error before 'typename'. That last one I had high hopes for.

Thanks, though.

CM
Which compiler version are you using?
Quote:Original post by SiCrane
Which compiler version are you using?

gcc 3.1. Would a more recent version handle things differently?

CM
I can get gcc 3.4.4 to accept the using Base<T>::Vector; line.
Quote:Original post by SiCrane
I can get gcc 3.4.4 to accept the using Base<T>::Vector; line.

Cool, thanks. using in this situation just feels more natural than the typedef I offered initially, so I think I'll get started on upgrading.

CM

This topic is closed to new replies.

Advertisement