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。
如何在这里使类模板参数推导有效?