I was having a discussion with a coworker about why the following does not compile in Visual Studio 2008:
class base
{
protected:
virtual void f(){}
};
class a : public base
{
public:
void fa(base* pb)
{
pb->f(); // error C2248: 'base::f' : cannot access protected member declared in class 'base'
}
};
He thinks this is perfectly reasonable but I think it's a strange restriction given, if I wanted base
and all of its derived classes to be a closed system, I still need to make some of base
's members public so they can all talk to each other through the shared interface they are all derived from publicly.
Is there some use case I'm not thinking of where allowing access to these protected members could break the nature of protected members?