#includeiostreamusing namespace std;class Max public int age; void mxint m_age age=m_age; int getid return age; ;int main Max m; mage=11; mmx15; coutmageendl; coutmgetidendl; 怎么修改使输出分别为1115
将getid()函数中的返回值改为age即可实现输出为11和15。
修改后的代码如下:
#include<iostream>
using namespace std;
class Max{
public:
int age;
void mx(int m_age){
age=m_age;
}
int getid(){
return age;
}
};
int main(){
Max m;
m.age=11;
m.mx(15);
cout<<m.age<<endl;
cout<<m.getid()<<endl;
}
原文地址: http://www.cveoy.top/t/topic/iUEz 著作权归作者所有。请勿转载和采集!