access private members in inheritance

后端 未结 6 1368
余生分开走
余生分开走 2021-01-31 17:23

I have a class A, which have a field val declared as private. I want to declare a class B, that inherit from A and have an access to val. Is there a way to do it on C++?

<
6条回答
  •  猫巷女王i
    2021-01-31 17:48

    You need to define it as protected. Protected members are inherited to child classes but are not accessible from the outside world.

提交回复
热议问题