Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the conflicts between structure and deconstruction and between father and son in C++ inheritance?

Shulou Source: shulou.com Published: 2022-06-02 11:29:00 10月06日 Update

This article is to share with you about the construction and deconstruction of C++ inheritance and the conflict between father and son. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

one。 Construction and deconstruction in inheritance

Q: how do I initialize parent class members? What is the relationship between the parent constructor and the subclass constructor?

a. Construction of subclass objects

1. A subclass can define a constructor

two。 Subclass constructor-the inherited member process must be initialized (initialized directly by initialization list or assignment, and initialized by calling the parent class constructor)

b. How the parent constructor is called in the subclass

1. Default call-applies to no-parameter constructors and constructors that use default parameters

two。 Display calls-calls are made through initialization lists and apply to all parent class constructors

Code example

# include # include using namespace std;class Parent {public: Parent () {cout

Tags: Functions subclasses members results runs parents and children examples conflicts code objects actions variables clocking content parameters methods more depth articles order Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia Apple MariaDB vpn