C++: Can a struct inherit from a class?

后端 未结 9 977
执笔经年
执笔经年 2020-12-07 14:39

I am looking at the implementation of an API that I am using.

I noticed that a struct is inheriting from a class and I paused to ponder on it...

First, I d

9条回答
  •  鱼传尺愫
    2020-12-07 15:05

    Yes, struct can inherit from class in C++.

    In C++, classes and struct are the same except for their default behaviour with regards to inheritance and access levels of members.

    C++ class

    • Default Inheritance = private
    • Default Access Level for Member Variables and Functions = private

    C++ struct

    • Default Inheritance = public
    • Default Access Level for Member Variables and Functions = public

提交回复
热议问题