I have a class A with nested class Inner_vector,
class A:
{
public:
class Inner_vector:public Vector
{
bool append(const class Element& element);
};
};
bool A::Inner_vector::append(const class Element& element)
{
add(element);
}
Now I want to derive a child class from A and also customize the “append” and “delete” methods of the inner class “Inner_vector” (mainly to add one new operation), so that the customized operations will be called instead. How could I do it? should I also derive a new nested class inside Child_A from A::Inner_vector as the following code
class Child_A: public A
{
public:
class Inner_Child_vector : public A::Inner_vector
{
bool append(const class Element& element);
};
};
bool Child_A::Inner_Child_vector::append(const class Element& element)
{
A::Inner_vector::append();
my_new_operation();
}
Or I do not need to derive from A::Inner_vector and directly rewrite it?
I really appreciate any help and comments.
In C++, inner classes are unrelated to the classes containing them except for scoping. So you have to derive the base’s inner class in the derived class.