Reputation: 1940
Let's say I have:
#include <Windows.h>
#include <iostream>
#include <vector>
std::vector<int> Base::m_intList;
class Base
{
public:
Base();
protected:
static std::vector<int> m_intList;
};
class Derived : Base
{
public:
Derived();
protected:
bool fWhatever;
};
class MoreDerived : Derived
{
public:
MoreDerived();
private:
HRESULT DoStuff();
};
Base::Base()
{
}
Derived::Derived()
{
}
MoreDerived::MoreDerived()
{
}
HRESULT MoreDerived::DoStuff()
{
for (auto it = m_intList.begin(); it != m_intList.end(); it++)
{
std::cout << *it;
}
}
When I try to compile this, I get "m_intList: cannot access inaccessible member declared in class 'MoreDerived'".
Question: Why can't I access a protected static member in the derived class's DoStuff function?
Upvotes: 2
Views: 372
Reputation: 141618
class Derived : Base
means class Derived : private Base
. The behaviour of private inheritance is:
protected
members of the base class become private
members of the derived class.private
members of the base class have no access as members of the derived class.So m_intList
is:
protected
in Base
private
in Derived
MoreDerived
hence your error.
Upvotes: 7