如何提醒一个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.