What is polymorphism in C, C supports two types of polymorphism at runtime

Updated on technology 2024-02-08
9 answers
  1. Anonymous users2024-02-05

    Polymorphism is when the same entity has multiple forms at the same time. It is an important feature of object-oriented programming (OOP). If a language only supports classes and not polymorphism, it only means that it is object-based, not object-oriented.

    Polymorphism in C++ is embodied in both running and compiling. Runtime polymorphism is dynamic polymorphism, and the specific objects it refers to cannot be determined until runtime. Compile-time polymorphism is static polymorphism, and at compile time you can determine the form in which the object will be used.

    In C++, there are the following ways to implement polymorphism: virtual functions, abstract classes, overloads, overrides, templates.

    The most used is the virtual function, and the template is also very good (STL is based on it), but the template is not very convenient to debug under Linux.

  2. Anonymous users2024-02-04

    In fact, polymorphism, to put it simply, means that there can be multiple forms, that is, you can abstract some series of common objects into an object, this object can be called a parent class, such as a dog or cat, can be abstracted into an animal, and then you can use the animal class to do some operations directly, you want to use it as a cat and then give it the characteristics of the cat, and if you want to use it as a dog, you can give it the characteristics of the dog, which can greatly simplify the programming.

  3. Anonymous users2024-02-03

    Polymorphism, in the simplest terms, is determined at runtime, which is also the simplest and most direct feature of judging whether polymorphism is or not. Anything that is not decided at runtime can be said to be polymorphic.

    Polymorphism is a very important feature of object-oriented programming, and it plays a very important role in programming.

    With polymorphism, you can treat different subclass objects as parent classes, shield the differences between different subclass objects, write common **, and make general programming to adapt to the changing needs.

  4. Anonymous users2024-02-02

    Did you know that a pointer to a base class can be assigned by a subclass's address?

    When you assign the address of a subclass to the base class pointer, and then call its function, the correct function will be selected according to the overload of the subclass.

    That's how I understand it.

  5. Anonymous users2024-02-01

    That is, n methods can be used to achieve the same goal.

  6. Anonymous users2024-01-31

    (1) Polymorphism at compile time.

    Compile-time polymorphism is achieved by overloading. For non-virtual members, the system decides what operations to implement based on the passed parameters, returned types, and other information at compile time.

    2) Polymorphism at runtime.

    Runtime polymorphism refers to the fact that it is not until the system is running that it is decided what to do based on the actual situation. In C++, runtime polymorphism is achieved through virtual members.

  7. Anonymous users2024-01-30

    Compile-time polymorphism corresponds to runtime polymorphism.

    Static polymorphic pairs are dynamic polymorphism.

    Both statements are true.

  8. Anonymous users2024-01-29

    A reference or pointer to a parent class to manipulate an object of a child class.

  9. Anonymous users2024-01-28

    C++ is a programming language, of course there is only one. But there are many different C++-based programming platforms.

    The programming language used on these platforms is C++, but there are some details that differ. I've worked with VC++, Symbian C++, and Borland C++, all of which are based on C++, but have slightly different programming styles or methods.

    You need to lay a good foundation for learning C++, and first learn the C++ language. When reading books, you can find some books called "C++ Programming Language" and the like, and only after learning the C++ language can you go to learn the programming tutorials of a certain platform.

    In general, there are two types of polymorphism, static polymorphism and dynamic polymorphism. Static polymorphism, also known as compile-time polymorphism, mainly includes templates and overloads. Dynamic polymorphism, on the other hand, is achieved through class inheritance and virtual functions, when the base class and subclass have a method with the same name and parameters returned, and the method is declared as a virtual method.

    When the base class object, pointer, and reference point to an object of the derived class, the base class object, pointer, and reference are calling the virtual function of the base class, but are actually calling the derived class function. This is called dynamic polymorphism.

    Implementation of static polymorphism.

    Static polymorphism is implemented by the compiler, simply put, the compiler modifies the original function name, in the C language, the function cannot be overloaded, because the C compiler simply adds an underscore in front of the function name when modifying the function" "However, after compiling from the gcc compiler, it is found that the function name does not change.

    The C++ compiler is different, it modifies the function name according to the type and number of function parameters, which makes the function can be overloaded, and in the same way, the template can also be realized, and the corresponding specialized function is generated for different types of arguments, and the function of different types of parameters can be distinguished by adding modifications.

Related questions
8 answers2024-02-08

string excelname= excelfileurl();The path to return to excel. >>>More

10 answers2024-02-08

First of all, a Class C has 254 addresses but there is always one as a gateway route, so there can be a maximum of 253 hosts. Then these hosts are public IP addresses. It can be done by setting up a LAN and using one IP. >>>More

4 answers2024-02-08

for(i=3;i<=ihuffsize[n-1];i++)uint_8s[0]=0;

uint_8s[1]=uint_8[p]; >>>More

6 answers2024-02-08

First of all, if you are wrong, if the value type is a global or static variable, it is assigned on the heap, and the local variable is allocated on the stack. The reference type is allocated on the heap, because the new comes out of the dynamically allocated memory, so both local and global are in the heap until the garbage user goes to it. In fact, memory allocation is basically the same form, and it has nothing to do with the language.