"C ++ Primer Third Edition" Reading Notes - Chapter 9 Overloaded Function

xiaoxiao2021-03-06  107

1. When a function name is declared in a special domain, the compiler explains the second (and subsequent) declarations as follows:

If the number or type of parameters in the parameter table of the two functions, the two functions are considered to be overloaded. If the return type of the two functions and the parameter table exactly match, the second declaration is considered the first repetitive declaration. The comparison process of the parameter table is independent of the parameter name. If the parameter table of the two functions is the same, the return type is different, the second is considered the first repetitive declaration, which is marked as a compilation error. The return type of the function is not enough to distinguish between two overload functions. If the parameter table of the two functions, only the default argument is different, the second declaration is considered the first repetitive declaration.

2. Judging whether the two functions are overloaded, only the parameters are pointers or references, const or valatile modifiers will work.

3. The programmer is best to hold this point: not every language feature is the next mountain you want to climb. Use the language characteristics should follow the logic of the application, not simply because it's existence must use it.

4. All functions in the overload function collection should be declared in the same domain.

5. USING declarations and USING indicators can make a member of a namespace in another, and these mechanisms have some impact on the declaration of overload functions.

6. The link indicator can only specify a function in the overload function set.

7. The overload allows the same function name to appear multiple times in different parameter tables, which is convenient for the lexation at the program source code level. However, the underlying component of most compilation systems requires each function name to be unique, because most link editors are in parsing external references in accordance with the function name. In order to deal with this problem, each function name and its parameter table are encoded as a unique internal name (eNCoded). Compilation system The underlying component can only see the name after the encoded name. Because this coding helps the link phase distinguishable function, we call it a type security link (Type-Safe Linkage).

8. Type Secure Links do not apply to functions declared with link indicator Extern "C". That's why the overload function set can only have a function that declares with the extern "C". 9. Three steps from Function Overload Resolution:

Determine the collection of overload functions (ie, candidate functions, Candidate function), determine the properties of the function calls in the function call. Select a function from the overload function, which can be called in the case where the reference number and the type of type are given. These functions are called a Viable function. Select the most matching function (i.e., the best feasible function, Best Viable function, or the best match function, Best match function).

10,

Editing ...

转载请注明原文地址:https://www.9cbs.com/read-96288.html

New Post(0)