Why would the conversion between derived* to base* fails with private inheritance?

后端 未结 7 478
栀梦
栀梦 2020-12-09 04:06

Here is my code -

#include
using namespace std;

class base
{
public:
    void sid()
    {
    }  
};

class derived : private base
{
public:         


        
相关标签:
7条回答
  • 2020-12-09 04:29

    You know that class derived inherits from class base, but the main() function doesn't know it. The reason the main() function doesn't know it is that you made class derived inherit PRIVATELY from class base.

    Therefore when you try to assign new derived to ptr, the pointer types are not compatible.

    0 讨论(0)
提交回复
热议问题