gpt4 book ai didi

c++ - 我在计算带有静态变量的对象总数的程序中出错

转载 作者:行者123 更新时间:2023-11-30 03:39:35 25 4
gpt4 key购买 nike

<分区>

using namespace std;
class Sample
{ int x;
static int count;
public:
void get();
static void showCount();
};
void Sample::get()
{
cin>>x;
++count;
}
static void Sample::showCount(){
cout<<"Total No. of Objects :"<<count;
}
int main()
{ Sample s1,s2;
s1.get();
s2.get();
Sample::showCount();
return 0;

}

编译错误:[错误] 无法将成员函数“static void Sample::showCount()”声明为具有静态链接[-fpermissive]

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com