Example Analysis of Constructor passing parameters to parent Class or this Class in C++
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