这个答案似乎表明它应该可以工作,所以为什么我的示例会引发编译器错误:
class Class1
{
protected:
long m_memberVar;
};
class SubClass1: public Class1
{
public:
void PrintMember(Class1 memberToPrintFrom)
{
Console::Write("{0}", memberToPrintFrom.m_memberVar); // <-- Compiler error: error C2248: 'BaseClassMemberAccess::Class1::m_memberVar' : cannot access protected member declared in class 'BaseClassMemberAccess::Class1'
}
};
[编辑] - 根据 Need4Sleep 的建议将子类更改为公共继承,但没有区别。