1 Different inheritance methods will change the access attributes of inherited members
public modified member variables and methods can be used both inside and outside the class.
protected modified member variables and methods are used inside the class and in inherited subclasses, and cannot be used outside the class. (It is for use in the family and for inheritance!)
Private modified member variables and methods can only be used inside the class and cannot be used outside the class
1) In C++ The inheritance method will affect the external access properties of the subclass
Public inheritance: The parent class members maintain the original access level in the subclass
Private inheritance: The parent class members become private members
protected inheritance: public members in the parent class will become protected
protected members in the parent class will still be protected
private members in the parent class will still be private
2) Private members still exist in subclasses, but cannot be accessed. No matter how you inherit a base class, a derived class cannot directly use the private members of the base class.
3) External access attribute table of subclasses in C++
Access level of parent class members
Inheritance method
public(继承方式) proteced(继承方式) private(继承方式) public public proteced private proteced proteced proteced private private private private Private
Three-look principle:
The inheritance method (public, private, protected) in C++ will affect the external access attributes of the subclass
Judge whether a certain sentence can Visited
1) Look at the calling statement. This sentence is written inside and outside the subclass
2) Look at how the subclass inherits from the parent class (public, private, protected)
3) Look at the access level (public, private, protected) in the parent class
Principles for setting the access level of derived class members
Thinking: How Proper use of public, protected and private to declare access levels for members?
1. Members that need to be accessed by the outside world are directly set to public
2. Members that can only be accessed in the current class are set to private
3. They can only be accessed in the current class Members accessed in classes and subclasses are set to protected, and the access rights of protected members are between public and private.
2 Type Compatibility Principle
The type compatibility rule means that wherever a base class object is required, an object of a public derived class can be used instead. Through public inheritance, the derived class obtains all members of the base class except the constructor and destructor. In this way, the public derived class actually has all the functions of the base class. All the problems that the base class can solve can be solved by the public derived class. The substitutions referred to in the type compatibility rules include the following situations:
Subclass objects can be used as parent class objects
Subclass objects can be directly assigned to parent class objects
Subclass objects can directly initialize parent class objects
Parent class pointers can directly point to subclass objects
Parent class references can directly refer to subclass objects
After substitution, derive Class objects can be used as objects of the base class, but only members inherited from the base class can be used.
Type compatibility rules are one of the important foundations of polymorphism.
The first level of meaning:
1-1 The base class pointer (reference) points to the subclass object
Parent *p = Null; p = &c1; p->printp(); 1-2 指针做函数参数 howToPrint(&p1); howToprint(&c1); 1-3引用做函数参数 howToprint2(p1); howToprint2(c1);
The second level of meaning
You can let the parent class object initialize the subclass object
Parent p3 = c1;
Object model in three inheritance
Question: How to initialize the parent class members? What is the relationship between the constructors of the parent class and the subclass?
When constructing the subclass object, you need to call the parent class constructor to initialize its inherited members
In the analysis of the subclass object When constructing, you need to call the parent class destructor to clean up its inherited members
The construction and destructor calling principle in inheritance (from top to bottom during initialization, first Dad has a son again)
1. When the subclass object is created, the constructor of the parent class will be called first
2. After the execution of the parent class constructor is completed, the constructor of the subclass will be executed
3. When the constructor of the parent class has parameters, the call needs to be displayed in the initialization list of the subclass
4. The order of calling the destructor is opposite to that of the constructor
The above is the eighth summary of C++ review points - inheritance one. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

C# is widely used in enterprise-level applications, game development, mobile applications and web development. 1) In enterprise-level applications, C# is often used for ASP.NETCore to develop WebAPI. 2) In game development, C# is combined with the Unity engine to realize role control and other functions. 3) C# supports polymorphism and asynchronous programming to improve code flexibility and application performance.

C# and .NET are suitable for web, desktop and mobile development. 1) In web development, ASP.NETCore supports cross-platform development. 2) Desktop development uses WPF and WinForms, which are suitable for different needs. 3) Mobile development realizes cross-platform applications through Xamarin.

The C#.NET ecosystem provides rich frameworks and libraries to help developers build applications efficiently. 1.ASP.NETCore is used to build high-performance web applications, 2.EntityFrameworkCore is used for database operations. By understanding the use and best practices of these tools, developers can improve the quality and performance of their applications.

How to deploy a C# .NET app to Azure or AWS? The answer is to use AzureAppService and AWSElasticBeanstalk. 1. On Azure, automate deployment using AzureAppService and AzurePipelines. 2. On AWS, use Amazon ElasticBeanstalk and AWSLambda to implement deployment and serverless compute.

The combination of C# and .NET provides developers with a powerful programming environment. 1) C# supports polymorphism and asynchronous programming, 2) .NET provides cross-platform capabilities and concurrent processing mechanisms, which makes them widely used in desktop, web and mobile application development.

.NETFramework is a software framework, and C# is a programming language. 1..NETFramework provides libraries and services, supporting desktop, web and mobile application development. 2.C# is designed for .NETFramework and supports modern programming functions. 3..NETFramework manages code execution through CLR, and the C# code is compiled into IL and runs by CLR. 4. Use .NETFramework to quickly develop applications, and C# provides advanced functions such as LINQ. 5. Common errors include type conversion and asynchronous programming deadlocks. VisualStudio tools are required for debugging.

C# is a modern, object-oriented programming language developed by Microsoft, and .NET is a development framework provided by Microsoft. C# combines the performance of C and the simplicity of Java, and is suitable for building various applications. The .NET framework supports multiple languages, provides garbage collection mechanisms, and simplifies memory management.

C# and .NET runtime work closely together to empower developers to efficient, powerful and cross-platform development capabilities. 1) C# is a type-safe and object-oriented programming language designed to integrate seamlessly with the .NET framework. 2) The .NET runtime manages the execution of C# code, provides garbage collection, type safety and other services, and ensures efficient and cross-platform operation.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
