Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of C++ Virtual function and static and dynamic binding

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the C++ virtual functions and static, dynamic binding example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

Override: if the method in the derived class, and a method inherited from the base class, return the same value, function name, and parameter list, and the method of the base class is a virtual virtual function, then the method of the derived class is automatically processed as a virtual function, and the relationship between them becomes an overlay; that is to say, the derived class will replace the virtual function inherited from the base class in its own virtual function table and replace it with the derived class's own.

Static binding: compile-time polymorphism, which is achieved by function overloading and templates, that is, the address of the calling function can be determined at the compile time, at the assembly code level, the call function name is presented.

Dynamic binding: run-time polymorphism, implemented by derived classes overriding the virtual functions of the base class. At the assembly code level, the call register is rendered, and the value of the register can only be determined when it is run.

There is no virtual function # include # include class Base {public: Base (int data = 10): ma (data) {} ~ Base () {}; void show () {std::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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report