. I've used public access qualifier, so the inherited members in ListArray should have the same access permissions as in ListBase. Can anyone explain why?
In lines 18 and 20 you're trying to access the '_size' of another instance of the class. Since you inherited from ListBase with public, '_size' is protected in ArrList too. Each instance has access only to its own private and protected members
struct A { protected: int i = 0 ; } ;
struct B : A
{
void foo() { i = 7 ; } // fine, B::i i inheried by B
void bar( B& b ) { b.i = 7 ; } // fine, B::i i inheried by B
void baz( A& a ) { a.i = 7 ; } // ***error, A::i i is not inheried by B
struct C : A {} ;
void foobar( C& c ) { c.i = 7 ; } // ***error, C::i
void barbaz()
{
this->i = 7 ; // fine, B::i
this->A::i = 7 ; // fine, B::i
A* This = this ;
This->i = 7 ; // ***error, A::i
}
};
Mmm you're right. That was embarrassing, I assumed and failed.
My next guess is that you're passing a pointer to the base class, which is considered a different class and therefore negates the access to its private members
ListBase is an abstract class - it has pure virtual functions, so one cannot create objects with this class. Did you create an object of type ArrList, and send a pointer to it to the function?
Edit Sending a pointer to the base class as an argument is OK because of polymorphism, but the pointer needs to come from a derived class.
Edit: Declaring a function to take a pointer to a base class as a parameter is OK, because of polymorphism, but the argument needs to be a pointer to the derived class.
So supplying a pointer to a derived class to a derived class constructor, is a bit weird. What are you wanting to do exactly?