2

我试图了解 value = T() 的含义以及如何解决它。该函数也是类的构造函数。

template<typename T>
Accumulator<T>::Accumulator(const T& value = T())
{
     total = value;
}

这不编译以下错误是:

error: default argument given for parameter 1 of `Accumulator<T>::Accumulator(const T&)'
error: after previous specification in `Accumulator<T>::Accumulator(const T&)'

基本上,该函数是具有默认参数的类的构造函数,如果给定参数的值,则将我的类的私有变量“total”设置为“value”。

4

1 回答 1

3

您应该只在函数声明的标头中指定默认参数。

于 2014-10-18T19:50:25.957 回答