Effective c++--experience Clause

Source: Internet
Author: User

Efficient C + +-template and generic programming

In C + +, the template embodies the compiler polymorphism, virtual embodiment of the run-time polymorphism.

On the double meanings of TypeName:

When declaring the template parameter, the meaning is exactly the same regardless of whether the keyword class or typename is used.

But C + + does not always treat class and TypeName as Deng Jian. Sometimes you have to use TypeName.

The name of the template internal bleeding is called a subordinate name if it is based on a template parameter. If the subordinate name is nested within class, we call her a nested subordinate name.

In summary, using a parameter type from another template in one template requires using TypeName to indicate that the variable being used belongs to a type in a template. At any time when you want to value a nested subordinate type name in the template, you must put the keyword in the previous position near him TypeName

Use TypeName to represent nested subordinate type names, but not as baseclass modifiers in the base class list or member initialization list (Member initial column).

When using new to request memory, if there is not enough memory space, there may be an exception, but you can set the function called when the exception occurs from the outside, Set_new_handler

Differentiate between interface inheritance and implementation inheritance:

function interface inheritance and function implementation inheritance, the differences between the two types of inheritance, much like the difference between function declarations and function definitions.

Sometimes you want derived classes to inherit only the interface of the member function (that is, the declaration); Sometimes you want derived classes to inherit the interface and implementation of the function at the same time, but also want to be able to override the implementation that they inherited; sometimes you want to derived Classes also inherits the interface and implementation of the function, and does not allow override of anything.

In fact, the above three cases correspond to three kinds of cases, namely pure virtual function, virtual function, and base class function

The purpose of declaring a pure virtual function is to allow derived classes to inherit only the function interface.

The purpose of declaring a simple impure virtual function is to have derived classses inherit the interface and default implementation of the function.

The purpose of declaring the Non-virtual function is to make derived classes the interface of the inherited function and a mandatory implementation.

Template-specific methods, the template for the specificity of the same as a template, but the parameters of this template is already defined, so the templates do not need to define TypeName. Equivalent to the overload of the template, except that the parameters of this template are already specified.

As mentioned in effective C + +, use const enum inline instead of # define, which means that the preceding can be substituted, because for # define, future replacements are always text. If there is a mistake or use a # define is not very appropriate, it may be compiled without error, but in the running process will be wrong, if you use the former to handle these, if they are wrong, they can be found in the compilation.

All compilers now implement virtual function using each class-specific virtual table, which is fixed in size and constructed before the program executes.

The main additional burden of C + + in layout and access time is caused by virtual.

Virtual function mechanism: to support an efficient "execution period binding"

Virtual base class is used to implement "multiple occurrences of a single, shared entity in the base class of the inheritance system"

The two mechanisms correspond to the Vptr VBTR subclass in the subclass with two pointers, respectively executing their

There are also additional burdens under multiple inheritance, which occur between "a derived class and its second or subsequent base class conversion".

Effective c++--experience Clause

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.