How is the folloing code working? MakeFinal constructor is protected, so it should not be accessible to FinalUser class. But I didn't get any build or execution error.
class MakeFinal
{
protected:
MakeFinal(void) {};
public:
~MakeFinal(void) {};
};
class Final : virtual public MakeFinal
{
public:
Final(void) {};
~Final(void) {};
};
class FinalUser : public Final
{
public:
FinalUser(void) {};
~FinalUser(void) {};
};
int main()
{
FinalUser *finalUserHeap_ = new FinalUser();
return 0;
}
Derived classes have access to protected members of their base classes. That's the difference between
protected
andprivate
.