Inheritance: 'A' is an inaccessible base of 'B'

后端 未结 6 1325
忘掉有多难
忘掉有多难 2020-11-28 21:51
$ cat inheritance.cpp 
#include 

using namespace std;

class A { };
class B : private A { };

int main() {
    A* ab = new B;
}
$
$ g++ inheritance.         


        
6条回答
  •  [愿得一人]
    2020-11-28 22:26

    Private inheritance means that outside the derived class, the inheritance information is hidden. That means you can't cast the derived class to the base class: the relationship isn't known to the caller.

提交回复
热议问题