Class Inheritance in Python: From ‘Child Inheriting Parent’s Business’ to ‘Open-Closed’ Programming Philosophy

Class Inheritance in Python: From 'Child Inheriting Parent's Business' to 'Open-Closed' Programming Philosophy

In the programming world of Python 3.12, class inheritance has long transcended the superficial understanding of “subclass reusing parent class code” and evolved into a deep architecture that embodies software design principles, type system constraints, and code evolution capabilities. This article will reveal five core dimensions of class inheritance in the context of Python 3.12, … Read more

A Comprehensive Guide to C++ Virtual Functions: From Underlying Principles to Practical Applications

A Comprehensive Guide to C++ Virtual Functions: From Underlying Principles to Practical Applications

It is well known that the polymorphism mechanism in C++ is one of the core aspects of object-oriented programming, and virtual functions are key to achieving polymorphism. Many developers can use them but often have a superficial understanding of their underlying mechanisms. Today, we will systematically clarify the working principles, usage scenarios, and precautions of … Read more

Understanding C++ Polymorphism: Implementation Principles and the Role of Virtual Function Tables

Understanding C++ Polymorphism: Implementation Principles and the Role of Virtual Function Tables

When you write Base* ptr = new Derived(); ptr->func(); in your code, have you ever stopped to think: how does the compiler know to execute the func() of the Derived class instead of the Base class? Clearly, the pointer type is Base, yet it can accurately find the implementation in the derived class — this … Read more

The Overhead of C++ Virtual Functions and Alternative Solutions

The Overhead of C++ Virtual Functions and Alternative Solutions

Part1The Core Concept and Underlying Implementation of Virtual Functions 1.1 Definition and Essence of Virtual Functions Virtual functions are the core mechanism for implementing dynamic polymorphism in C++, essentially realized throughruntime binding to achieve the design philosophy of “base class interface, derived class implementation”. In the base class, the virtual keyword is declared, and derived … Read more

In-Depth Analysis of Virtual Functions and Constructors/Destructors in C++

In-Depth Analysis of Virtual Functions and Constructors/Destructors in C++

In-Depth Analysis of Virtual Functions and Constructors/Destructors in C++ Exploring key techniques and underlying implementations in object-oriented programming In C++ object-oriented programming, the virtual function mechanism is central to achieving polymorphism. However, when virtual functions are used in conjunction with special member functions (especially constructors and destructors), there are many details and considerations that require … Read more

Exploring Function Pointers in C Language (Part 3)

Exploring Function Pointers in C Language (Part 3)

Continuing the discussion on pointers in C language, one of the powerful features is the function pointer, which brings unprecedented flexibility and extensibility to your code. What is a Function Pointer? A function pointer, as the name suggests, is a pointer variable that points to a function. It stores the memory address of a function, … Read more

Where is the C++ Virtual Function Table Located?

Where is the C++ Virtual Function Table Located?

In general, the combination of inheritance and virtual functions in C++ provides us with polymorphic behavior. Today, we will explore the underlying mechanics of virtual function pointer calls and the location of the virtual function table in memory. Let’s write a basic C++ program to verify this: #include <iostream> class Base { public: Base() = … Read more

Embedded C Language – Object-Oriented Programming

Embedded C Language - Object-Oriented Programming

Object-Oriented Programming vs. Procedural Programming Procedural Programming (POP): Focuses on functions, achieving program functionality through function calls. Data and functions are separate. For example, C is a typical procedural language. When developing a student grade management system, data structures are defined to store student information, followed by writing functions to implement adding, deleting, modifying, and … Read more

Understanding Object-Oriented Programming in Embedded C

Understanding Object-Oriented Programming in Embedded C

1. Introduction 1.1 Background and Significance With the widespread application of embedded systems across various industries, C language has long dominated embedded development due to its efficiency, direct hardware access, and cross-platform advantages. However, as the complexity of system functions increases, the traditional procedural programming model often leads to chaotic code structure, high coupling, and … Read more

Decoding the Myths of Qt/C++ Arrays and Polymorphism: From Memory Layout to Container Optimization

Decoding the Myths of Qt/C++ Arrays and Polymorphism: From Memory Layout to Container Optimization

1. Basic Type Arrays and Caching Arrays are a contiguous block of memory, making them ideal for caching as they provide fast sequential access and allow O(1) time complexity random access when the index is known. Code Example:<span>int</span>, <span>char</span>, <span>byte</span> (i.e., <span>quint8</span>) arrays #include <QDebug> #include <QtGlobal> // For quint8 void basicArrayExamples() { // 1. … Read more