选择题
下面程序的输出结果是______。
#include<iostream. h>
class example
{
int a;
public:
example(int b) {a=b++;}
void print() {a=a+1; cout<<a<<' ';}
void print()const {cout<<a<<' ';}
};
void main()
{
example x(3);
const example y(2);
x. print();
y. print();
}
A、
2 2
B、
4 3
C、
4 2
D、
3 2
【正确答案】
C
【答案解析】
“++”是右结合的,所以先赋值为3,最后输出3+1;常成员函数只有常对象才能调用,所以输出2。
提交答案
关闭