In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you what is the use of = delete in Category 11. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can gain something through the detailed introduction of this article.
In Category 11, when we define a member function of a class, if we use "= delete" to modify it, it means that the function is defined as deleted, which means that the member function can no longer be called, otherwise an error will occur.
# include class TestClass {public: int func (int data) = delete;}; int main (void) {TestClass obj; obj.func; return 0;}
A direct error is reported at compile time, as follows
Before Category 11, when we wanted a class not to be copied, we defined the constructor as private, but we didn't need to do this in Category 11, we just need to add = delete after the constructor to modify it.
Ingenious usage
Here is an ingenious use of = delete. There will be a lot of implicit type conversions in C++, as follows
# include class TestClass {public: void func (int data) {printf ("data:% d\ n", data);}}; int main (void) {TestClass obj; obj.func (100); obj.func (100.0); return 0;}
The output is as follows
When we pass 100.0 to obj.func (), an implicit type conversion occurs, from double to int. Sometimes we don't want this conversion to happen. We just want the parameters passed in to be the same as the specified type, so we can use = delete to do this, as follows
# include class TestClass {public: void func (int data) {printf ("data:% d\ n", data);} void func (double data) = delete;}; int main (void) {TestClass obj; obj.func (100); obj.func (100.0); return 0;}
We modify the overloaded function whose parameter type is double with = delete to indicate that the function is deleted, so the user cannot use this function, and there will be an error in recompilation.
The above is what is the use of = delete in Clippers 11. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.