初冀 2022-11-03 21:01 采纳率: 61%
浏览 6
已结题

这个代码为什么运行出来结果不是整数?

include

using namespace std;
class Point {
public:
Point(int age) {
this->age;
}
int age;
void add(Point& p) {
this->age += p.age ;
}
};
void test01() {
Point p1(10);
Point p2(12);
p2.add(p1);
cout << p2.age << endl;
}
int main() {
test01();
return 0;
}
结果是一大串数字

  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2022-11-03 21:04
    关注

    Point(int age) {
    this->age = age; //你没给成员变量赋值啊
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月11日
  • 已采纳回答 11月3日
  • 创建了问题 11月3日