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 > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to talk to you about the scope of private in C++, which many people may not quite understand. In order to make you understand better, the editor summarized the following content for you. I hope you can get something from this article.
Why variables declared as private in a class can be called directly by the copy constructor in this class and can also be compiled through.
As a C++ engineer, I haven't thought about this problem carefully all the time, and recently I suddenly realized that this is a very interesting question. Simply do the next verification, the original we usually mentioned public, protected, private decorated with class, not the corresponding instance of class.
That is to say, as long as the function of private is in class, it can be called. As for why it cannot be called directly by the instance after instantiation, it is not because the instance cannot be called, but because the instantiated operation is not within this class, and the scope is outside the class, which leads to the variable that cannot be called private directly.
In order to confirm this conclusion, the following program is specially done, and the Test (Apoca) function is deliberately implemented, and it is found that there is no problem with the compilation.
Examples are as follows:
The copy constructor and the Test () function are both private members that call the input parameter directly, so there is no problem with Gateway + compilation.
The running result is as follows:
After reading the above, do you have any further understanding of the scope of private in C++? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.