C + + Learning Path (10): implementation efficiency introduced by virtual inheritance

Source: Internet
Author: User

This article does not know what name to take, for the moment so called, directly to see the scene to understand. An excerpt from the Deep Exploration of C + + object model

Point3D origin, *pt = &origin;

(1) origin.x = 0;

(2) pt->x = 0

Both of these code execution results are the same, but are there any differences in execution efficiency?

(1) If Point3D is a normal struct, ordinary class, ordinary single inheritance or multiple inheritance, the execution efficiency of member X is exactly the same, because X's position in the class is offset and fixed at compile time (no virtual function is introduced). (2) If Point3D is virtual inherited from a base class, then PT cannot be determined at compile time to point to which class type, that is, cannot determine the offset position of x at compile time. Therefore, this access operation must be deferred to the executor, which can be resolved by an additional indirect boot, and the execution efficiency is slower than (1)

C + + Learning Path (10): implementation efficiency introduced by virtual inheritance

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.