不能将此类初始值设定项用作函数调用
class SomethingElse
{
public:
Something<float> mSomething(100);
};
您需要使用等号或括号内的初始值设定项。例如
class SomethingElse
{
public:
Something<float> mSomething { 100 };
};
这是一个演示程序。
template <typename t>
class Something
{
public:
Something(t theValue) {mValue=theValue;}
t mValue;
};
class SomethingElse
{
public:
Something<float> mSomething{ 100 };
};
int main()
{
}
根据C++语法
member-declarator:
declarator virt-specifier-seqopt pure-specifieropt
declarator brace-or-equal-initializeropt
identifieropt attribute-specifier-seqopt: constant-expression
参见术语
大括号或同等初始值设定项
.