请问这段代码那里错了!我编译时老显示有一个错误

来源:百度知道 编辑:UC知道 时间:2024/06/21 19:17:19
#include <iostream.h>

class Student
{
public:
Student(int numble=0)
{
studentnb++;
numble=2100+studentnb;
cout<<"numble is:"<<numble<<endl;
}

~Student()
{
cout<<"has been delete:"<<studentnb<<endl;
studentnb--;
}

static int getStudentnb()
{
return studentnb;
}

protected:
static int getStudentnb();
static int Student::studentnb;
};

int Student::studentnb=0;

void fun()
{
Student s1;
Student s2;
cout<<Student::getStudentnb()<<endl;
}

void main()
{
fun();
cout<<Student::getStudentnb()<<endl;

}
改了还是运行不了。。。。

本人不太懂C++,但也发现如下错误

1、static int getStudentnb(); 此行重复定义了,此行不必写,若一定要写,建议写到前面
2、static int Student::studentnb; 此行这样写: static int studentnb;
3、void main() 此行一般是 int main() 虽然程序没有返回什么

程序运行结果:
numble is:2101
numble is:2102
2
has been delete:2
has been delete:1
0