class Base { public: int a; protected: int b; private: int c; }; class Derived : Base { int d; friend Friend; }; class Friend { Derived

Anh Vũ

New member
class Base
{
public: int a;
protected: int b;
private: int c;
};
class Derived : Base
{
int d;
friend Friend;
};
class Friend
{
Derived derived;
};</blockquote>
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
 

Minh Thoa Mai

New member
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.