Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of Constructor passing parameters to parent Class or this Class in C++

Shulou Source: shulou.com Published: 2022-06-03 14:04:50 11月14日 Update

This article mainly introduces the example analysis of passing parameters from the constructor to the parent class or this class in C++, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take everyone to know it.

In the constructor of C++, the subclass inherits the parent class, so when you create a subclass member, you can pass parameters to the parent class or the subclass constructor at the same time, as follows:

Write an example: mul_argc.c

# include # include using namespace std; / / League of Legends class class Hero {private: int blood; string name; public: Hero (int blood = 100,string name = "man wang") {this- > blood = blood; this- > name = name;} ~ Hero () {if (this- > blood < 0) {cout

Tags: Functions articles examples subclasses examples analysis at the same time values examples interests members methods more friends knowledge ribbons alliances heroes industries information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Apple Redmi NVidia OPPO Reno