#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();
}
有人知道为什么输出的y是地址么
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-