I tried the following compilable piece of code:
#include <iostream>
using namespace std;
class A {
public:
class X {
public:
X () {
i_ = 1;
}
int getI() {
return i_;
}
protected:
int i_;
};
int getX() {
return xobject_.getI();
}
protected:
X xobject_;
};
class B : public A {
public:
class X : public A::X {
public:
X() {
i_ = 5;
}
int getI() {
return i_;
}
protected:
int i_;
};
protected:
X xobject_;
};
int main (int argc, char** arv) {
B b;
std::cout << "value of b.getX(): " << b.getX() << std::endl;
return 0;
}
Output:
value of b.getX(): 1
This answers both questions. If I don't redefine the function getX()
and the vector x_vector
in the subclass, the super class members will be used.