【发布时间】:2019-06-27 06:08:21
【问题描述】:
// 我在其他有关静态变量及其初始化的问题中找到了有用的信息。我找到了一个解决方法(不觉得像这里建议的那样用一个单独的文件来解决这个问题:Initialize static variables in C++ class?),但这将是一个解决方案,以便能够使用静态变量作为累加器在特定实例上执行的操作通过他们的方法。
很抱歉浪费了时间,我认为这个问题对社区没有任何价值,应该关闭。
尝试打印两个静态累加器的静态函数 mostrarTotal() 不起作用,因为它们的定义不正确。
class Vendedor {
private:
static double sumatot;
static double comtot;
public:
static void mostrarTotal();
};
//Static method to print static variables sumatot and comtot
void Vendedor :: mostrarTotal() {
cout << "Las ventas totales fueron: " << sumatot << " para una comisión de: " << comtot;
}
int main () {
//This line throws the error
Vendedor::mostrarTotal();
return 0;
}
【问题讨论】:
-
Vendedor::mostrarTotal();
标签: c++ static-functions