-2
如果我尝试执行下面的程序,那么它会给出错误。静态成员函数抛出错误
#include <iostream>
using namespace std;
class book {
static int i;
public :
static void set_data(void) // static member function
{
i++;
cout<<i<<endl;
}
};
int book :: i = 0;
int main()
{
cout<<book :: set_data() << endl; // trying to display the static member function data here but it is giving error
}
如果我们想要使用静态成员函数,那么是否需要我们需要返回静态参数?
寻求调试帮助的问题('**为什么不是这个代码工作?**')必须包含所需的行为,特定的问题或错误以及在问题本身中重现**的最短代码** 。没有**明确问题陈述**的问题对其他读者没有用处。请参阅:[如何创建最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。 – Biffen
你试图打印''set_data()'这是'void'的返回值,它只是没有意义。 – songyuanyao
不是问题,但不要使用'std :: endl',除非你需要额外的东西。 ''\ n''结束一行。 –