C++ inheritance - inaccessible base?

后端 未结 2 1104
梦谈多话
梦谈多话 2020-11-28 05:15

I seem to be unable to use a base class as a function parameter, have I messed up my inheritance?

I have the following in my main:

int some_ftn(Foo          


        
相关标签:
2条回答
  • 2020-11-28 05:47

    By default, inheritance is private. You have to explicitly use public:

    class Bar : public Foo

    0 讨论(0)
  • 2020-11-28 06:10

    You have to do this:

    class Bar : public Foo
    {
        // ...
    }
    

    The default inheritance type of a class in C++ is private, so any public and protected members from the base class are limited to private. struct inheritance on the other hand is public by default.

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