2

Why do I need to specify using in the below example?

If not specified, there would be an ambiguous call to operator()

template <typename ... T>
struct C : T ... {
   // not having this using...
   // would emit a compiler error
   // like  member 'operator()' is ambiguous
   //using T::operator()...;
};

// template class guidance feature of C++17
template <typename ... T>
C(T...) -> C<T...>;

int main(){
   C c { []{}, [](int){} };
   c(3);
}
Kobi
  • 832
  • 1
  • 9
  • 16
  • Another related question here, why there is no need for constructor here? Is this really a POD? Is the default generated constructor doing std::forward(t)... ? – Kobi May 17 '17 at 20:42
  • As for regular inheritance. – Jarod42 May 17 '17 at 20:42
  • 3
    There is nothing to `forward` in default constructor. – Jarod42 May 17 '17 at 20:43
  • Re regular inheritance- got it. I totally forgot about it. – Kobi May 17 '17 at 20:46
  • Looking at Jason's Turner C++ weekly (ep 49,50), he had std::forward done in the constructor. but std::visit example in cppreference does not have any constructor in the "overloaded" struct. So I was wondering why. And another question is why there is no need for a constructor here that takes the lambdas ? – Kobi May 17 '17 at 20:48

0 Answers0