# Getting around typename deprecation

## Recommended Posts

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::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

Try just:

using Vector;

##### Share on other sites
Quote:
 Original post by SiCraneTry just:using Vector;

I thought of that. Unfortunately, it is a parse error.
Quote:
 templates.cpp:11: parse error before ;' tokentemplates.cpp:12: warning: `typename Derived::Vector' is implicitly a typenametemplates.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

##### Share on other sites
Which compiler version are you using?

##### Share on other sites
Quote:
 Original post by SiCraneWhich compiler version are you using?

CM

##### Share on other sites
I can get gcc 3.4.4 to accept the using Base<T>::Vector; line.

##### Share on other sites
Quote:
 Original post by SiCraneI can get gcc 3.4.4 to accept the using Base::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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627746
• Total Posts
2978897

• 10
• 10
• 21
• 14
• 14