有如下程序: #include using namespace std; class Point{ public: Point(int xx=0,int yy=0):x(xx),

admin2015-06-27  12

问题 有如下程序:
       #include
       using namespace std;
       class Point{
       public:
           Point(int xx=0,int yy=0):x(xx),y(yy) { }
           void SetX(int xx) { x=xx; }
           void SetY(int yy) { y=yy; }
       private:
           int x,y;
       };
       class Circle:public Point{
       public:
           Circle(int r):radius(r) { }
           int GetRadius() { return radius; }
       private:
           void SetRadius(int r) { radius=r; }
           int radius;
       };
       int main(){
           Circle c1(5);
           c1.SetX(1);             //①
           c1.SetY(2);             //②
           c1.SetRadius(10);       //③
           cout<           return 0;
       }
在标注号码的语句行中存在语法错误的是

选项 A、①
B、②
C、③
D、④

答案C

解析 本题考查对象成员的引用,在类外引用对象的数据成员时,只能访问public成员而不能访问private成员所以C选项错误。
转载请注明原文地址:https://kaotiyun.com/show/E9BD777K
0

最新回复(0)