1

Suppose I have the following template class:

template <typename T>
struct Hello
{
    struct Hi {};
};

I want to be able to create a function like this:

template <typename U>
void hello_hi(typename Hello<U>::Hi&)
{}

And use it like this:

int main()
{
    hello_hi(Hello<int>::Hi{});
}

But C++ isn't able to deduce the type U because it is a template argument of of Hello, not Hi. Is there some way I can deduce U without setting it explicitly as a template argument of hello_hi?

Justin
  • 24,288
  • 12
  • 92
  • 142
Romário
  • 1,664
  • 1
  • 20
  • 30
  • 1
    As is, this is impossible. However, you could still provide a way to access the outer type's template parameter from the inner type, such as via a type alias (`struct Hi { using the_type = T; };`) – Justin Aug 25 '20 at 18:00

0 Answers0