Can you Hide a virtual method in c++?
c++, visual-c++
Solution
Why anyone would do something like that? It breaks base class contract. If you don't want to implement subclass that has the same interface as base class, why do you inherit at all? Use composition.
There is no equivalent of C# new keyword in C++. So you cannot cancel method's 'virtualness'.
If you really want to do this you can always:
override a method in subclass as private.
create overload. But the overload has to have different parameters.
But if you do this, IMHO something is wrong with your design. I wish each C++ compiler caught both of this situations at least as warnings.
Problem
I have a base class with a virtual function. ``` virtual CString& Foo(); ``` I want to overload this in subclass like so ``` CString Foo(); ``` is there a way to hide the base classes virtual function? Something like the new keyword in vb.net or C#