c++的问题(新手)

来源:百度知道 编辑:UC知道 时间:2024/06/02 21:25:17
这个我是按书上打的为什么不能运行?~不知道是哪里错了~~
我用的是VC~

#include <iostream>
using namespace std;
class xuesheng
{private:
int xuehao;
int fenshu;
public:
void shuru()
{cin >>xuehao;
cin >>fenshu;
}
void shuchu()
{cout <<xuehao <<endl;
cout <<fenshu <<endl;
};
};
Student stud1,stud2;
int main()
{
stud1.shuru();
stud2.shuru();
stud1.shuchu();
stud2.shuchu();
return 0;
}
出错提示~
007.cpp(17) : error C2146: syntax error : missing ';' before identifier 'stud1'
007.cpp(17) : error C2501: 'Student' : missing storage-class or type specifiers
007.cpp(17) : fatal error C1004: unexpected end of file found

Student stud1,stud2;

Student改成xuesheng

有什么提示不,比如什么错误?

我晕。你明明定义的是class xuesheng
你用的时候怎么成了 Student stud1,stud2;
。。。Student 当然会出现错误了