Sign in to follow this  
Conner McCloud

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this