问题 单项选择题

下面程序的输出结果是( )。  # include <iostream.h>  class example  {    int a;  public:    example (intb) {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。

单项选择题
单项选择题