I am lost. I have a class Editor and a class Controller. Classes WorkflowEditor and WorkflowController derive from Editor and Controller respectively. Class Controller has a protected member Editor editor and class WorkflowController has a private member WorkflowEditor editor (with same name).
Edit from EitanT:
Here’s a simplified code snipped to illustrate what the OP has described:
class Controller
{
Editor editor;
// ...
}
class WorkflowEditor : public Editor {
// ...
};
class WorkflowController : public Controller {
WorkflowEditor editor;
// ...
};
My application is a module with graphical interface. In workflow mode, a ribbon appears on Launch, and a wizard is displayed. On click on one button, a method in class Controller is called. Execution crashes because at this time, Editor editor class member of object with type Controller is dead. I would like class member Editor editor to be the same as class member WorkflowEditor editor (same name).
In other words, if a class A has a member of class B and class childA (derived from A) has a member of class childB (derived from B), and member of type childB and B have same name, isn’t the member “inherited”?
The object is inherited, but is not the same object as the one declared in the derived class. The derived class member is a separate object to the base class member, even though they have the same name. Technically, it hides the base class member, making it accessible only with its qualified name,
Controller::editor.You can achieve what you want with a virtual function, which you override in the derived class to access an object contained there: