views:

300

answers:

1

Hi everyone,

I have a small problem with my compiler (VC++ 6.0). In my opinion, such a code should cause 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 is compiled and run under VC++ 6.0 without any problem.

Regarding SW-Design, this code is not perfect. None of the class member members should be declared as public. But I am not interested in this aspect.

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

Does anybody have an explanation to this phenomenon?

Thanks in advance

Necip

+7  A: 

This behavior is a non conformance in VC++6.0, you should have got an error when defining Derived::z. (Excepted if you have business reasons to use it, there are other choices technically preferable to VC++6.0 which is old).

AProgrammer