Boolan C + + Object-oriented advanced programming learning Week Fifth

Source: Internet
Author: User

This week, C + + object-oriented advanced programming is mainly about three aspects

1. Virtual tables and virtual pointers

Virtual pointers: If there is a virtual function in the class (including the parent class), there must be a virtual pointer, which is a virtual table pointing to the virtual function.

Virtual table: A table of a class that a virtual pointer points to, and a pointer to the implementation of a virtual function inside a class on a table

Here the virtual function and the virtual table are generally combined with the multi-nature of the class to use, the subclass calls the virtual function by calling the virtual pointer to call the virtual function table inside the pointer again to implement the function characteristics

This method of invocation is called dynamic binding, which is an object that is automatically judged by the pointer type, which can be used to invoke the corresponding function without distinguishing which object in the implementation.

The function inside our normal invocation class is called static binding.

2. Const

A lot has been mentioned in the previous study of Const, which is explained in more depth today.

From this table we can see that the constant object can not call the very amount of the function

So when we write some class member functions, if this class does not change the class members, try to add a const

Otherwise, there is a constant object, but the question of the member function cannot be called

3, New and delete

Before we briefly introduced new and delete, here is the main explanation for the overloads of new and delete

The overloaded mode is divided into

1. Global overloading

2. Overloading in class

3, placement overload

One of the placement overloads here is that after we reload new (XX,XX), we also reload the delete (xx,xx), but we

No other version of Delete is invoked at the time of invocation, and the corresponding version of Delete is invoked only when placement new throws an exception.

Some versions don't appear here either.

Boolan C + + Object-oriented advanced programming learning Week Fifth

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.