Why does protected inheritance cause dynamic_cast to fail?

前端 未结 3 1804
心在旅途
心在旅途 2020-12-10 00:03

I changed my C++ base class to be protected inheritance and my dynamic_cast(s) stopped working.

Why should changing the inheritance to

3条回答
  •  囚心锁ツ
    2020-12-10 00:25

    Private (or protected) inheritance is semantically different from public inheritance. It is not a "is-a" relationship but a "implemented in terms of" relationship.

    Meaning that you can't use a base class as a handle to a derived object.

提交回复
热议问题