[英]Class template argument deduction of member variables
In C++17 I am allowed to use Foo
in the following example without empty template argument brackets thanks to class template argument deduction: 在C ++ 17中,由于类模板参数推导,我可以在以下示例中使用
Foo
而不使用空模板参数括号:
template<typename T = int>
struct Foo{};
int main(){
Foo f; // before C++17 you had to write "Foo<> f;"
}
Why am I not allowed to use the same syntax for class members? 为什么我不允许对类成员使用相同的语法?
template<typename T = int>
struct Foo{};
struct Foo2{
Foo f{}; ///< error: invalid use of template-name 'Foo' without an argument list
};
int main(){
Foo2 f2;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.