Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report