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--
This article mainly introduces "the example usage of explicit type conversion operator in Category 11". In daily operation, I believe that many people have doubts about the example usage of explicit type conversion operator in Category 11. Xiaobian consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful to answer the doubts about "the example usage of explicit type conversion operator in Craft 11". Next, please follow the editor to study!
Type conversion operator
Look at the following example:
This is the prototype of a plural class that defines a type conversion operator of type double. Once you have it, you can use it like this:
The output is as follows:
Complex does not support output operators, so the compiler tries to convert C1 to double and output later. So far so good.
Do you really want to convert to double?
Take a look at the following code:
From a mathematical point of view, it should output 2.23606. But in fact, this code doesn't even pass compilation. The reason for this is that there are two options for this code compiler: one is to convert C1 to double and then add 1; the other is to convert 1 to plural (1q0i) and then perform plural addition.
I need an idea from a programmer.
Explicit type conversion operator
One way to eliminate ambiguity is to use explicit to disable implicit double type conversions. The code is as follows:
Because implicit type conversions cannot be performed, the following code has a compilation error:
This is not a big deal, because it is not easy to tell whether the conversion to double output is correct in itself. The plural output function is already provided in the code through output operator overloading.
The output is as follows:
At this point, the study of "instance usage of the explicit type conversion operator in Cellular 11" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.