开发者

virtual inheritance with abstract class constructors

开发者 https://www.devze.com 2023-04-05 11:22 出处:网络
I got the following problem: There is an abstract base class, and two other abstract classes which virtually inherit from the base class, and as a conclusion have to call the Constructor of it, with a

I got the following problem: There is an abstract base class, and two other abstract classes which virtually inherit from the base class, and as a conclusion have to call the Constructor of it, with all the needed arguments.

But now, I got a "normal" class which does inherit both second order classes, and therefor has to call the baseclass-constructor on its own (as t开发者_运维技巧he base class is inherited virtually from both the second order classes), but both of the second order constructors take arguments to pass on to the base class constructor.

Is it possible to somhow implement the constructors in a way that there will be no need to pass those, in that case unused, arguments?

I hope I was able to precisely describe my problem, if there are any questions I will be happy to answer them.


FINALLY found it.

§ 12.6.2 / 7 [class.base.init]

The expression-list or braced-init-list in a mem-initializer is used to initialize the designated subobject (or, in the case of a delegating constructor, the complete class object) according to the initialization rules of 8.5 for direct-initialization. The initialization performed by each mem-initializer constitutes a full-expression. Any expression in a mem-initializer is evaluated as part of the full-expression that performs the initialization. A mem-initializer where the mem-initializer-id denotes a virtual base class is ignored during execution of a constructor of any class that is not the most derived class.

So, pass the arguments. They'll be ignored anyway. Makes things really simple!

0

精彩评论

暂无评论...
验证码 换一张
取 消