Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the abandoned multiple inheritance in C++?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "what is the abandoned multiple inheritance in C++". Many people will encounter this dilemma in the operation of actual cases. then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

After learning about C++ 's inheritance, have we ever wondered whether a class is allowed to inherit from multiple parent classes? Then in C++, it is supported to write code with multiple inheritance, that is, a subclass can have multiple parent classes. At this time, the subclass has all the member variables of the parent class, the subclass inherits all the member functions of the parent class, and the subclass object can be used as any parent class object. The syntax for multiple inheritance is shown below, which is essentially the same as single inheritance!

Class Derived: public BaseA, public BaseB {/ /...}

Let's take the code as an example to analyze it.

# include using namespace std;class BaseA {int ma;public: BaseA (int a) {ma = a;} int getA () {return ma;}}; class BaseB {int mb;public: BaseB (int b) {mb = b;} int getB () {return mb;}}; class Derived: public BaseA, public BaseB {int mc Public: Derived (int a, int b, int c): BaseA (a), BaseB (b) {mc = c;} int getC () {return mc;} void print () {cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report