简体   繁体   中英

Constructors can only be inherited DIRECTLY from the base?

I have a base class A, that defines some constructors.

Then I have classes B1, B2, B3 that inherit from A.

None of these are meant to be instantiated. Instead, I have classes C11, C12, C13 inheriting from B1, and so on.

C11, C12 etc. all need A's constructors.

I don't think I can write using A::A; in class C11, for instance, right?

The only way to get these constructors (other than cutting and pasting them) is for B1 to say using A::A; and C11 to say using B1::B1; ?

Note my question isn't about what a particular compiler supports, but what the spec allows, so "just test it" isn't really an answer to this particular question.

If you are looking for a quote from the standard, then here goes:

[namespace.udecl]/3 ... If a using-declarator names a constructor, its nested-name-specifier shall name a direct base class of the class being defined.

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