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

后端 未结 9 966
执笔经年
执笔经年 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:03

    Yes a struct can inherit from a class. struct and class differ only in the access-specifier assumed for the members and for a base classes (or structs) if not specified explicitly in C++ . For structs it's public. For classes it's private.

    The sentence you quote from the manual is about the concept of a class in C++, as compared to the concept of a data structure in C. In C++ new keyword - class was introduced to better reflect the change in the concept, but for compatibility with code in C, an old keyword struct was left and it's meaning is as described above.

提交回复
热议问题