0

In C++17, consider a base template class that has an alias to get the vectorized type of the enclosed type:

template<typename T>
struct Foo {
    using VectorType = vector<T>;
};

In a non-template derived class, we can simply use VectorType as:

struct Bar : public Foo<int> {
    VectorType Get(VectorType t) { return t; }
};

Now if we want to use it in a template derived class, we need to use using typename:

template<typename T>
struct BarT : public Foo<T> {
    using typename Foo<T>::VectorType;

    VectorType Get(VectorType t) { return t; }
};

From what I initially thought, it should be possible to be deduced automatically by the compiler, no?

Is there any better way such that I don't have to retype it for multiple aliases in the derived classes?

cigien
  • 57,834
  • 11
  • 73
  • 112
ashura
  • 13
  • 3

0 Answers0