简体   繁体   中英

Where is the original of the statement “the most derived class's ctor needs to directly call the virtual base class's ctor”?

While I learn how to implement a final class in C++, I find such a statement:

"the most derived class's ctor needs to directly call the virtual base class's ctor."

However, I can't find the original of the statement in the C++ standard. (N3126)

Who can tell me the exact page number?

Thanks in advance.

In C++03, it's § 12.6.2 5

Initialization shall proceed in the following order:

— First, and only for the constructor of the most derived class as described below, virtual base classes shall be initialized in the order they appear on a depth-first left-to-right traversal of the directed acyclic graph of base classes, where “left-to-right” is the order of appearance of the base class names in the derived class base-specifier-list.

...

In the current draft for C++0x (N3126), it's § 12.6.2 10, which is page 270:

In a non-delegating constructor, initialization proceeds in the following order:

— First, and only for the constructor of the most derived class (1.8), virtual base classes are initialized in the order they appear on a depth-first left-to-right traversal of the directed acyclic graph of base classes, where “left-to-right” is the order of appearance of the base classes in the derived class base-specifier-list

...

N3126 is not the C++ standard.

It's a draft for the upcoming C++ standard.

But anyway, the info about initialization is in the section about initialization for derived classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM