In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about the parts that are difficult to understand about CPP. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can gain something according to this article.
Inheritance:
It is divided into public inheritance, private inheritance and protective inheritance.
1. Public inheritance (public)
The characteristic is that the public members and protected members of the base class remain as they are as members of the derived class, while the private members of the base class remain private and cannot be accessed by the subclasses of the derived class.
Such as:
Class room
{
Public:
Int A1 = 50
Private:
Int b1 = 70
}
Class bed: public room
{
Public:
Int C1 = A1
Int c2 = b1umbram / error report
}
two。 Private inheritance (private)
The characteristic of private inheritance is that both the public and protected members of the base class are private members of the derived class and cannot be accessed by subclasses of the derived class. Private members of the base class are still inaccessible
Such as:
Class desk: private room
{
Public:
Int f = a _ 1 _ pockets / correct
Int g = b1umbram / error, private members of the base class are still inaccessible
}
Class chair: public desk
{
Public:
Int c = A1 _ handle / error reporting is inaccessible, so it cannot be accessed by a subclass of a derived class
}
3. Protect inheritance (protected):
The characteristic of protected inheritance is that all public members and protected members of the base class become protected members of the derived class and can only be accessed by its derived class members and friends. Private members of the base class are still private.
Here is an introduction to Youyuan:
Friend function: friend ()
Friend class: friend class
Friends have no inheritance.
Polymorphism: this is the core object-oriented concept of C++, mainly through virtual function virtual, which allows subclasses to redefine parent virtual functions in member functions (see the example of virtual functions below). This is called overriding or rewriting (note that it is not overloaded).
Overloading: overloading is multiple function names, but one (two) parameter names or types are different, and the compiler automatically generates some preprocessing functions with different names based on these parameters.
The real difference between polymorphism and overloading is whether the function address is determined before running. Because overloading requires the compiler to generate some preprocessing functions with different names, it can not determine the address of the function until it is run.
Virtual function: that is, virtual, there is no virtual function, there is no polymorphism, we can see its importance. The virtual function enables the pointer of the parent object to call the function of the subclass. If it is not a virtual function, the parent class cannot call the subclass. The implementation of polymorphism in C++ is implemented only when a virtual function is called through a base class pointer.
Class animal {virtual void breathe () / / Note that this is the concern function {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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.