-
Virtual functions are the key to introducing polymorphism and inheritance.
It's okay if you say that!
-
You're confusing the concept of function overloading with virtual functions.
A function overload is when multiple functions have the same function name, but their function parameter lists are different, whether it is the type of the parameter or the data of the parameter, that is, their function signature (the function signature is composed of the name of the function and the parameters of the function) is different.
Virtual functions are different, they have exactly the same function signature, except that there are multiple versions of the function definition. And to realize the relationship between the two classes of the virtual function, there must be a relationship between the parent class and the child class, and not all class member functions are OK.
Virtual functions are designed to implement the polymorphism of object-oriented programming.
Supplement: The most commonly used implementation method of virtual functions is implemented with a function pointer table. If you first understand the polymorphism in object-oriented programming, it may be better to look at the principle of virtual functions.
-
Yes, the overloading of functions occurs at compile time, while virtual functions are determined at runtime. In fact, it is sometimes called static polymorphism for overloading of functions, and dynamic polymorphism for virtual functions.
-
Virtual and overloaded functions of the base class.
1) If there is no function with the same name, and no derived class is defined, the virtual function is not an overloaded function;
2) If there is a function with the same name, it is an overloaded function.
3) If a derived class is defined and the derived class overloads the virtual function (the pure virtual function must be overloaded, the virtual function is not necessarily overloaded).
Then the virtual function of the base class must be an overloaded function.
An overloaded function is one that has the same name as other functions.
When a virtual function is called with a base class pointer and reference, if the object that the pointer or reference actually points to or represents is an object of the derived class, and the derived class overrides the virtual function, then the virtual function overloaded by the derived class is called, not the virtual function of the base class. This is how object-oriented polymorphism is implemented in C++.
A virtual function is a function that is expected to be overloaded by a derived class.
A purely virtual function is a function that the derived class must overload!
A pure virtual function is a type of virtual function;
This is the relationship between virtual functions and overloaded functions.
PS: Again, overloading is only related to the function name, and the parameters can only indicate whether it can be overloaded or not;
The destructors and constructors of the base and derived classes don't seem to be overloaded??? This doesn't seem to be clear.
The different constructors of the class are also overloaded.
1) If the base class does not define any derived classes, then a virtual function without a function of the same name is not an overloaded function;
2) If the base class defines a derived class and none of the derived classes overload a virtual function, then the virtual function of the base class without the function of the same name is still not an overloaded function;
3) If there is any function with the same name, then a function is an overloaded function regardless of whether it is a virtual function or not;
4) If the derived class and the base class define any function with the same name, it is a function overload.
5) If the virtual function is redefined in the derived class, it must be overloaded;
6) If there is a class with pure virtual functions, and there is a fully implemented version of the derived class (which can define objects), then all pure virtual functions must be overloaded.
7) The destructors of the base and derived classes must be overloaded if they are virtual functions (this is the only explicit function overload of a function with a different name).
-
A virtual function is declared in the base class and decorated with virtual, but it is not implemented, only when the subclass inherits from the base class.
An overloaded function is a method that overrides the base class by re-implementing (the base class is already implemented) when a function already exists in the base class when the subclass inherits.
Virtual functions and methods overloaded in subclasses and base classes have the same name, the same parameter type, and the same return value type. My personal feeling is that virtual functions are a special kind of overload, that is, functions that must be overloaded (general functions can not be overloaded).
DefWindowProc and WindowProc are both ** processing message API functions, and DefWindowProc handles messages that are not processed by WindowProc. However, in the scenario of your program, cmfcwnd is a subclass of cframewnd, and only calling defwindowproc cannot achieve all the cframewnd characteristic messages, and you must call the message handler of the parent class.
define the function void f(int q, int w, int e=0);
e=0 is the default argument, when the function is called f(1,2), then e=0 >>>More
using systme;
using ; >>>More
Method:
The rand() function is used to generate random numbers, however, the internal implementation of rand() is implemented using the linear congruence method, which is a pseudorandom number and can be considered random within a certain range due to the long period. >>>More
You can use function pointers, such as:
voidfunction(int >>>More