下列程序的输出结果是 #include<iostream.h> class Myclass{ public : Myclass( int i=0,int j=0) {x=i;

admin2013-05-30  26

问题 下列程序的输出结果是        #include<iostream.h>        class Myclass{          public : Myclass( int i=0,int j=0)            {x=i;             y=j;            }            void show( ){cout<<"x="<<x<<" "<"y="<<y<<endl;}            void show( )const{cout<<"x="<<" "<<"y="<<y<<endl;}            privated:                int x;    int y;            };          void main( )        { Myclass my l (3,4);          const my2(7,8);          my l.show( );my2.show( );}

选项 A、x=4,y=3;x=7,y=8
B、x=3,y=4;x=7,y=8
C、x=7,y=8;x=4,y=3
D、x=8,y=7;x=7,y=8

答案1

解析 在Myclass类中定义了两个同名函数show,其中一个是常成员函数。在main函数中定义了两个对象myl,my2,其中对象my2是常对象。这两个对象调用成员函数show时,通过对象myl调用的是没有用const修饰的一般成员函数,而通过对象my2调用的是const修饰的常成员函数。
转载请注明原文地址:https://kaotiyun.com/show/rUNp777K
0

最新回复(0)