In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
C++ static different applications are how, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
There are many differences between C++ programming language and other languages, especially C language. Well, today, we can analyze the differences between C++ and static from the application method. At the same time, it allows you to further master the programming methods of C++ language.
C++ static specific application code example:
Public class C {public static void M () {Console.WriteLine ("call in class C");} public class D: C {public new static void M () {Console.WriteLine ("call in class D");}} public class E where T: C {public static void N () {T.M ();}}
The code is wrong and one instance is not allowed to call a static method. If you compile, it will prompt:
Error 2'T'is a 'type parameter'
Which is not valid in the given context
Why? From a language design point of view, only one of the following three cases is true for the above code.
1. It's the wrong way to write it.
2. E.N () calls C.M () no matter what T is.
3. E.N () calls C.M () but E.N () calls D.M ().
If you follow the 2 design, there will be users who expect to execute class D's method M instead of C when T is class D. Static is a static because it can be exactly determined at compile time, or this method can be determined during the static code analysis phase. Therefore, if we design according to the way of 3, we will violate this principle. In this way, there is only one left.
Another explanation:
1. Virtual static, why is there no such thing?
two。 There is no this pointer (the above is transferred from a colleague's blog with a simple modification)
However, it is not clear why C++ is allowed to do so.
Public class Test {public static void Say () {}} Test t; Test* T2 = new Test (); t.Say (); T2-> Say (); after reading the above, have you mastered how C++ static is applied in different ways? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.