三年之约-第二年 2021-12-14 22:36 采纳率: 0%
浏览 22

有人知道为什么输出的y是地址么

#include
using namespace std;
//常量和引用必须通过类内初始值或构造函数初始化列表进行初始化
class student
{
const int x;
int& y; //类内初始值
public:
student(int a, int b) :x(a), y(b) {} //初始化列表
void display()
{
cout << x << " " << y;
}
int f(int xx) const
{
return xx + x;
}
};
int main()
{
student y(10, 20);
y.display();
}

  • 写回答

2条回答 默认 最新

  • 关注

    输出的是10 20
    不是地址啊

    评论

报告相同问题?

问题事件

  • 创建了问题 12月14日