conversion from derived * to base * exists but is inaccessible

后端 未结 1 876
南笙
南笙 2021-02-02 05:09

Why does the follwing code produce this error even though c is a struct and has a public inheritance by default??

struct c 
{
protected:
    int i;
public:
    c         


        
相关标签:
1条回答
  • 2021-02-02 05:23

    You need:

    class d : public c
    

    class inheritance is private by default.

    When you privately inherit from a class or a struct, you explicitly say, among other things, that direct conversion from a derived type to a base type isn't possible.

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