C++问题 求详细解答 5
#include<iostream>usingnamespacestd;classStudent{public:Student(intn,floats):num(n),s...
#include <iostream>
using namespace std;
class Student
{public:
Student(int n,float s):num(n),score(s){}
void change(int n,float s){num=n;score=s;}
void display(){cout<<num<<" "<<score<<endl;}
private:
int num;
float score;
};
int main()
{Student stud(101,78.5);
Student const *p=&stud;//这里是题要求的
p->display();
p->change(101,80.5);
p->display();
return 0;
}
请问为什么运行不了 展开
using namespace std;
class Student
{public:
Student(int n,float s):num(n),score(s){}
void change(int n,float s){num=n;score=s;}
void display(){cout<<num<<" "<<score<<endl;}
private:
int num;
float score;
};
int main()
{Student stud(101,78.5);
Student const *p=&stud;//这里是题要求的
p->display();
p->change(101,80.5);
p->display();
return 0;
}
请问为什么运行不了 展开
2个回答
展开全部
去掉const可以运行……加上const意味着指针指向不能改变
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
using namespace std;
class Student
{
public:
Student(int n,float s):num(n),score(s){}
void change(int n,float s){num=n;score=s;}
void display(){};//{cout<<num<<" "<<score<<endl;}
private:
int num;
float score;
};
int main()
{
Student stud(101,78.5);
Student *p=&stud;//这里是题要求的
p->display();
p->change(101,80.5);
p->display();
return 0;
}
using namespace std;
class Student
{
public:
Student(int n,float s):num(n),score(s){}
void change(int n,float s){num=n;score=s;}
void display(){};//{cout<<num<<" "<<score<<endl;}
private:
int num;
float score;
};
int main()
{
Student stud(101,78.5);
Student *p=&stud;//这里是题要求的
p->display();
p->change(101,80.5);
p->display();
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询