• Advertisement
Sign in to follow this  

Getting around typename deprecation

This topic is 4521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
I can get gcc 3.4.4 to accept the using Base<T>::Vector; line.

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
Sign in to follow this  

  • Advertisement