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

后端 未结 7 506
栀梦
栀梦 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:15

    You need to declare your sid() function in the base class as virtual. A virtual function can be replaced by a derived class. Otherwise, you would likely get a compiler error.

提交回复
热议问题