Search code examples
c++templatesinheritancedependent-name

Unhide templated cast operator from templated base class


I have a templated base class with a templated conversion operator. I would like to unhide this templated conversion operator in a derived class (because of dependent-name lookup).

template <class T>
class A
{
public:
  template <class U>
  operator A<U>() const { ... }
};

template <class T>
class B : public A<T>
{
public:
  template <class U>
  using A<T>::operator A<U>;
};

Is there a way to do this? The above code doesn't work, because it tells me I cannot template a using declaration.


Solution

  • A using-declaration cannot refer to a template-id, to a namespace, to a scoped enumerator, to a destructor of a base class or to a specialization of a member template for a user-defined conversion function.