In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.