Object-oriented correlation

Source: Internet
Author: User

Overloading, overriding, reusing
Scopes: Overloaded functions, which have the same scope, and override and reuse function scopes that appear in the inheritance relationship.
Overloading: The function name must be the same, but the function argument list must be different, and the return value does not matter.
Override: Function name, parameter list and return value type must be the same. Appears in virtual functions, also called Overrides.
Reuse: The function name is the same, appearing in the derived class reuse defines its base class function name, also known as hidden. Hidden functions can be called by scope. Reuse embodies a rule in C + +-name lookup precedes type checking.

Base class scope and derived class scope
Derived class scopes are nested within the scope of the base class, so that derived classes can use their members as members of their own (in cases where the derived class has access rights).

Virtual functions
The overriding mechanism and dynamic binding-the invocation of which virtual function is determined by the type of the caller (derived class or base class), i.e. the function body of the function cannot be judged at compile time, and the intelligence is judged at runtime.
Virtual functions cannot be decorated as static.
Implementation of the virtual function table:
The virtual function table consists of VTBL (virtual table) and vptr (virtual table pointer).
VTBL is usually a function pointer array or a linked list.
Virtual functions in VTBL are stored in the order they are declared, and if the derived class overrides the virtual function of its base class, the location of its parent class is substituted in its vtbl.
In multiple inheritance, each base class with virtual functions has its own VTBL, and the virtual function members of derived classes (non-inheritance or overrides) are placed in the vbtl of the first base class.
In multi-inheritance, derived classes require extra 4N of space to store pointers to virtual function tables, where n is the number of virtual functions contained in all its base classes.

Virtual inheritance
1. The construction of the virtual base class is the responsibility of the lowest derived class, in which the virtual base class is ranked first, regardless of its position in the inheritance system.
2. When multiple virtual base classes appear, the construction order of these virtual base classes is related to their location. This position is related to the subtree in multiple inheritance, which is constructed first by the sub-tree order.

Multiple inheritance
1. The name lookup takes place simultaneously in all the direct base classes of the derived class, with each direct base class being a subtree of the root tree; If the lookup is found in more than one subtree (subtree with the direct base class as Root), two is ambiguous.
2. Two semantics are legal, and no error occurs if you do not invoke a member function that has ambiguity. Defining a new version of this member function in a derived class resolves the two semantic issue.

Name Lookup
1. Scope lookup (first Name) class > base class > Namespace
2. Overload resolution (formal parameter)
3. Accessibility detection (Access)

Three factors that affect the size of a class
1. Language features effects of breakfast, such as VTBL.
2. The compiler optimizes processing in special cases, such as for empty classes, where the compiler assigns a byte to its object to differentiate the addresses of individual objects.
3. Boundary adjustment, through alignment to optimize the transmission efficiency of the bus.

Block copy construction and assignment constructs

Object-oriented correlation

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.