|
发表于 2009-11-3 03:22:32
|
显示全部楼层
IP:江苏扬州
以下是引用心动音符在2006-6-11 16:10:01的发言:
人们为什么说C++难!难在哪里啊?
#include <iostream>
using namespace std;
class Student
{public:
Student(int n,float s):num(n),score(s){}
void display() const;
void change(int n,float s); //去掉const因为你在定义时要改变num,score的值.
private:
int num;
float score;
};
void Stundet::change(int n,float s)//Student 写错了
{num=n;score=s;}
void Student::display() //少了const
{cout<<num<<" "<<score<<endl;}
int main()
{
const Student stud(101,78.5); //应该把const去掉,因为你下面要调用chang()函数.
stud.display();
stud.change(101,80.5);//常对象只能调用常成员.
stud.display();
return 0;
}
这题错哪了 |
|