In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces how the copy constructor function in C++ is, the content is very detailed, interested friends can refer to it, I hope it can help you.
Copy of common variables
Sometimes we define one variable and initialize it with another.
int a_variable=12;int new_variable(a_variable);
It's useful to initialize yourself with an existing variable of the same type.
Is it possible to copy custom types of objects easily through an existing object?
copy constructor
Copy constructor is also called copy constructor, it has only one parameter (since you need to copy, one is enough, if you pass two identical objects there is no meaning, if you pass two different objects, there is no need to call copy constructor), the parameter type is a reference to this class.
If the programmer does not write a copy constructor, the compiler automatically generates a copy constructor that copies byte by byte according to the member variables in the copy constructor (beginners can understand this, in fact, individual compilers do not always automatically generate copy constructors, they may directly copy the values of the source object to the corresponding member variables of the target object, which will be described later).
class MyDate{ int day_; int year_;public: MyDate(int day, int year) { day_ = day; year_ = year; } MyDate(const MyDate& date) { day_ = date.day_; year_ = date.year_; 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.