I have code like this:
template <typename T>
struct bar
{
typedef T type;
};
template <typename T>
struct sub_bar : bar<T>
{
typename bar<T>::type x;
};
I know that this is recommended way, but I want write code like this:
template<typename T>
struct sub_bar : bar<T>
{
...
type x;
};
How to do it? I think I can do something like this:
template<typename T>
struct sub_bar : bar<T>
{
typedef typename bar<T>::type type;
type x;
};
Is it ambiguous what's type? However this code works with gcc9 compiler.
I would tend to use a trick of forcing qualified lookup and write
to avoid repeating the template arguments of the base class (and to avoid potential ambiguity in a strange situation where both classes were searched for
type
), but what you wrote definitely works.