如何提醒一个param传递给基类构造函数? [英] How to remind a param passed to the base class constructor?

查看:125
本文介绍了如何提醒一个param传递给基类构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个成员并传递相同的基类可以工作如果:

Having a member and pass the same to the base class works if:

DerrivedClass::DerrivedClass(SomeParamType* p)
    : BaseClass(p),
      derrivedClassMember(p),
{
 ...
}

...但是如何共享而不将它作为param传递给DerrivedClass构造函数?这是有效的吗?或者是derrivedClassMember此时未初始化?

... but how to share without passing it as param to the DerrivedClass constructor? Is this valid? Or is the derrivedClassMember not initialized at this time?

DerrivedClass::DerrivedClass()
    : BaseClass(derrivedClassMember),
      derrivedClassMember(new SomeParamType()),
{
 ...
}

我不能改变基类的实现。

I'm not able to change the base class implementation.

推荐答案

那时。在初始化 derrivedClassMember 之前调用基类构造函数。这是因为派生类的派生成员或构造函数可能依赖于基类的成员。

It is not initialialized at that time. The baseclass constructor is called before the derrivedClassMember is initialized. That's because the derived members or the constructor of the derived class may depend on members of the baseclass.

这篇关于如何提醒一个param传递给基类构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆