As many of the guys said this is legal.
However, the IS-A part is not so simple. When it comes to "dynamic polymorphism", the relationship is "IS-A", Ie everything you can do with Super, you can also do with an instance of Derived.
However, in C ++, we also have what is often referred to as static polymorphism (patterns, most of the time). Consider the following example:
class A { public: virtual int m() { return 1; } }; class B : public A { private: virtual int m() { return 2; } }; template<typename T> int fun(T* obj) { return obj->m(); }
Now, when you try to use "dynamic polymorphism", everything looks fine:
A* a = new A(); B* b = new B();
... but when you use "static polymorphism", you can say that the "IS-A" relationship no longer holds:
A* a = new A(); B* b = new B();
So, in the end, changing the visibility for a method is βpretty legitimate,β but it's one of the ugly things in C ++ that can lead to errors.
Eugene loy
source share