如何使类模板参数推导在类内部起作用?

时间:2019-02-23 13:55:31

标签: c++ templates c++17 template-deduction class-template

MCVE:

template <typename T>
struct S
{
  S(T) {
      S s{nullptr}; // expect S<std::nullptr_t>, but it is S<T> 
  };
};

int main()
{
  S{42};
}

在这里,我希望将s的类型推导为S<std::nullptr_t>,但推论为the type name S is treated as an injected-class-name, which refers to S<T>,因此推论为an error

如何在这里使类模板参数推导有效?

0 个答案:

没有答案
相关问题