Technical experts detail how to compile C ++ source code

Source: Internet
Author: User

The Visual C ++ 6.0 compiler is responsible for compiling the C ++ source code into an assembly file and converting it into an obj file.) then, it uses the connector to connect the related intermediate files, generate executable binary files. I hope this article will teach you more.

1. The concept of Polymorphism
Polymorphism refers to the use of a name to define different functions, which execute different but similar operations to achieve "one interface, multiple methods ". The implementation of polymorphism is related to static Association and Dynamic Association. The polymorphism supported by static Association is known as the polymorphism at compilation, also known as static polymorphism, which is implemented through function overloading and operator overloading. The polymorphism supported by dynamic Association is known as the Runtime polymorphism, also known as dynamic polymorphism, which is implemented through inheritance and virtual functions.

2. Function Overloading
Function overloading means that he can use the same name to access a group of related functions. In a class, common member functions and constructor functions can be reloaded. In particular, the constructor overload provides multiple initial activation methods. This gives users more flexibility.

There are two types of function overloading in the base class and derived class: one is the overload with different parameters. The other is the overload with no difference in parameters, but they belong to different classes. You can use either of the following methods to distinguish between these two functions: object names and class names.


3. Operator overload dynamic Polymorphism
It is implemented through inheritance and virtual functions. The operator overload is implemented by creating the operator function operator. An operator function defines the operations to be performed by an overloaded operator. This operation usually applies to a class. In this way, when an operator function @ with the name operator @ is encountered during compilation, it indicates the type of the parameter passed to the function.

The overload operator is used in the same way as the predefined operator. It cannot change the number of parameters of the original operator to a single object or a binary object. It cannot change the combination of the original priority. You cannot define new operators. You can only select an appropriate operator overload from the existing operators in the C ++ source code.

A member operator function can be defined as a member of the class to be operated by it. It can also be defined as a non-class member, but most non-member operator functions are class-friendly functions called youyuan operator functions ). The Declaration format of the member operator function in the class is:

4. Value assignment operator
Inherits the C language, and user-defined classes and structures must be able to be assigned values. The array name cannot be assigned a value. The array name is essentially a constant pointer. For any class, the C ++ Source Code provides the default value assignment operator. Generally, the default value assignment operator overload is competent. When there is a pointer type in the class, you need to customize the value assignment operator function. Generally, the function body contains two parts: similar to the destructor, canceling the resources occupied by the object;

Similar to the constructor, what is the basis for the trial? Br> the value assignment operator overload "=" of a class can only be used as a member function, and cannot be used as a friend function.
Operator = () cannot be inherited.
The differences between the copy constructor and the value assignment operator are as follows: the Declaration and definition methods are different; the call methods are different.

5. C ++ source code
A virtual function is another form of overload. It allows the connection between the virtual function call and the function body to be established at runtime. Definition: a virtual function is a function defined by the keyword virtual in the base class and redefined in the derived class. When a new definition is defined in the derived class, its original form includes the return type, function name, the order of the number and type of parameters must be the same as that in the base class.

  • Introduction to function overloading in C ++
  • Reference functions and variables in C ++ in C
  • Advanced technical scholars compile C ++ code
  • Detailed description of C ++ compilation and code Problems
  • Describes various programming skills of C ++.

The constructor cannot be a virtual function, but the Destructor can be a virtual function. Relationship between virtual functions and overload functions: When a common function is overloaded, its function parameters or parameter types must be different, and the function return types can also be different. In a derived class, when you redefine a virtual function, the function name, return type, number of parameters, and type and order of parameters must be exactly the same as the original function type in the base class;

If only the return type is different and the rest are the same, the system will give an error message. When a virtual function is overloaded, if only the function name is the same, and the number, type, or sequence of parameters are different, the virtual function feature will be lost. Multi-inheritance and virtual functions: Multi-inheritance can be viewed as a combination of multiple single-inheritance.

6. Pure virtual functions and abstract classes
Pure virtual function: a virtual function described in the base class. It is not defined in the base class, but must define its own version in its derived class, or re-describe it as a pure virtual function. Common form of pure virtual functions: virtual type func_name parameter table) = 0type indicates the function return type, and func_name indicates the function name ). Abstract class: A class must have at least one pure virtual function. Abstract classes provide a unified interface for processing different Derived classes and assign the implementation responsibility to the derived classes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.