C++帮忙看看哪错了?

来源:百度知道 编辑:UC知道 时间:2024/07/13 04:50:53
#include<iostream.h>
#include<stdlib.h>
class student{
public:
student()
{
++x;
cout<<"\nplease input student NO.";
cin>>sno;
}
static int get_x()
{
return x;
}
int get_sno()
{
return sno;
}
private:
static int x;
int sno;
};
int student::x=0;
void main()
{
cout<<student::get_x()<<" student exist\n";
student stu1;
student *pstu=new student;
cout<<student::get_x()<<" student exist,y="<<get_sno()<<endl;
cout<<student::get_x()<<" student exist,y="<<get_sno()<<endl;
}
操作符乱用?没有啊
就是双冒号啊

#include<iostream.h>
#include<stdlib.h>
class student
{
public:
student() { ++x; cout<<"\nplease input student NO.";cin>>sno; }
static int get_x() { return x; }
int get_sno() {return sno; }
private:
static int x;
int sno;
};
void main()
{
student stu1;
student *pstu=new student;
cout<<stu1.get_x()<<" student exist\n";
cout<<pstu->get_x()<<" student exist,y="<<pstu->get_sno()<<endl;
cout<<pstu->get_x()<<" student exist,y="<<pstu->get_sno()<<endl;
}

你的::操作符是乱用的吧。