In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
The knowledge points of this article "how to achieve Polymorphism and Virtual functions in C++" are not quite understood by most people, so the editor summarizes the following, with detailed contents and clear steps, which can be used for reference. I hope you can get something after reading this article. Let's take a look at this "how to achieve polymorphism and virtual functions in C++" article.
(1) Polymorphism
Polymorphism refers to different behaviors when the same message is received by different objects. The so-called message refers to the calls to the class member functions, and different behaviors refer to different implementations, that is, different functions are called.
1) Classification of polymorphisms
In a broad sense, polymorphism refers to the ability of a program to deal with multiple types of objects. In C++, this polymorphism can be done through overloading polymorphism (function and operator overloading), forced overloading (type casting), and type parameterized polymorphism (templates).
Including four ways to implement polymorphism (inheritance and virtual functions). Type parameterized polymorphism and inclusion polymorphism are called general polymorphism, which are used to systematically describe a group of types that are semantically related; overload polymorphism and mandatory polymorphism are called special polymorphism, which are used to describe the relationship between semantically unrelated types.
Virtual functions are used in C++ to implement inclusion polymorphism. Virtual functions provide C++ with a more flexible polymorphic mechanism, which can only be determined when the program is running, so virtual functions are the essence of polymorphism, and classes that contain at least one virtual function are called polymorphic classes. Inclusion polymorphism is frequently used in object-oriented programming.
2) static binding
Binding, also known as binding, is the process of merging modules or functions together to generate executable code, assigning a memory address to each module or function and providing the correct memory address for external access.
Binding a function implementation to a function call during the compilation phase is called static binding. Static binding must know all the information needed for the execution of all functions and modules during the compilation phase, and its choice of functions is based on the type of pointer (or reference) to the object. In C language, all links are static; in C++, static links are also common.
Class Point {public: void area () {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.