class Base { public: int a; protected: int b; private: int c; }; class Derived : Base { int d; friend Friend; }; class Friend { Derived derived; }; In the following code, which of the following variables can be accessed in “Friend”?

class Base

{

public: int a;

protected: int b;

private: int c;

};

class Derived : Base

{

int d;

friend Friend;

};

class Friend

{

Derived derived;

};

In the following code, which of the following variables can be accessed in “Friend”?

A. only a and b

B. a,b and c

C. only a

D. error

Hướng dẫn

Chọn D là đáp án đúng

Xem lời giải

Xem lời giải

Việc khai báo class Derived : Base có nghĩa là class Derived kế thừa kiểu private từ class Base.

Do vậy, các member của class Derived (kể cả class Friend) không thể access member của class Base.

 

Đánh giá chủ đề này
How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site