Private typedef visible in derived class

I have a little problem with my compiler (VC ++ 6.0). In my opinion, such code should throw an error;

class Base
{
    private:
        typedef int T;
};

class Derived : private Base // Here the Base class can be inherited publicly as well. It does not play any role
{
    public:
        T z;
};



int main()
{
    Derived obj;
    obj.z = 7;
    return 0;
}

      

This code snippet compiled and ran under VC ++ 6.0 without problems.

As far as SW-Design is concerned, this code is not perfect. None of the class members should be declared public. But that doesn't interest me.

My problem is with the typedef. Typedef is declared private in the Base class. From my point of view of understanding in C ++, this typedef should not be visible to either the Derived class or the main () function. But both can see them perfectly.

Does anyone have an explanation for this phenomenon?

Thank you in advance

Nejeep

+2


source to share


1 answer


This behavior is a mismatch in VC ++ 6.0, you should get an error when defining Derived :: z. (Excluded if you have business reasons for using it, there are other options that are technically preferable for VC ++ 6.0, which is old).



+7


source







All Articles