I’m trying to create the constructor of a nested class, which inherits from a parent nested class, using its constructor. Basically:
DerivedList<T>::DerivedNested::DerivedNested(DerivedNode*& ptr)
: BaseList<T>::BaseNested::BaseNested(ptr)
{}
The prototype of the constructor of my BaseNested goes like this:
BaseList<T>::BaseNested::BaseNested(BaseNode*& ptr)
(and is required to get the ptr parameter by reference since it needs the address of said pointer in its code)
I figured I had to cast my DerivedNode* to a BaseNode*, but : a static_cast::BaseNode*>(ptr) finds no matching functions since it isn’t a reference, and a static_cast::BaseNode*&>(ptr) gives an invalid cast error.
The same goes for dynamic_cast. A reinterpret_cast compiles, but gives something incorrect during excecution.
Does anyone know how I could call that parent constructor?
If you think you need a reference, that’s probably because you want to modify the pointer later. The problem is that the type of the pointer in the derived class is
DerivedNode*, andBaseNode*in the base class. What if the base class affects aDerivedNode2*to its pointer ?You should use setters, or move the logic from the base class to the derived ones.