My question really says it all but i'll just reiterate the problem.
In class A there is a protected variable I am trying to access (a vector).
Class B is a subclass of class A and, in its constructor, can access and add to this vector as it likes.
However, in class C (which is a subclass of class A) I would like to add to this vector in its constructor, but the compiler tells me off.
Here is my code:
Class A:
class ClassA
{
protected:
std::vector<Object *> myVector;
};
Class B:
class ClassB : ClassA, AnotherClass
{
public:
ClassB()
{
this->myVector.push_back(new Object);
}
}
Class C:
class ClassC : public ClassB
{
public :
ClassC()
{
this->myVector.pushBack(new Object);
}
}
Can anyone tell me if what I'm doing is impossible due to constraints of C++ or because of my code?
Thanks as always.