弱问:初学vc静态成员,出错:'Student' followed by 'int' is illegal (did you forget a ';'?)
#include<iostream.h>
class Student
{
public:
Student(int StudentNo=0)
{
cout<<"creat one student\n" ;
NoOfStudents++;
cout<<"NoOfStudents"<<NoOfStudents;
StudentNo = 9022100 + NoOfStudents;
cout<<"StudentNo"<<StudentNo<<endl;
}
~Student()
{
cout<<"destruct one student \n";
NoOfStudents--;
}
static int number()
{
return NoOfStudents;
}
protected:
static int NoOfStudents;
int StudentNo;
}
int Student::NoOfStudents=0;
void fn()
{
Student s1;
Student s2;
cout<<Student::number()<<endl;
}
void main()
{
fn();
cout<<Student::number()<<endl;
}
出错:
--------------------Configuration: 静态成员 - Win32 Debug--------------------
Compiling...
aaa.cpp
C:\Dev-Cpp\静态成员\静态成员\aaa.cpp(26) : error C2628: 'Student' followed by 'int' is illegal (did you forget a ';'?)
C:\Dev-Cpp\静态成员\静态成员\aaa.cpp(26) : error C2371: 'protected: static int Student::NoOfStudents' : redefinition; different basic types
C:\Dev-Cpp\静态成员\静态成员\aaa.cpp(23) : see declaration of 'protected: static int Student::NoOfStudents'
Error executing cl.exe.
aaa.obj - 2 error(s), 0 warning(s)