Is quotient means different things in C ++ and C #?

I was wondering why C # does not allow the private virtual function and comes across aptly named Why are private virtual methods illegal in C #?

In the accepted answer, Eric Lippert (who probably knows what he is talking about ...) said:

If you want to limit the ability to override a method in non-nested derived classes, you can do this by limiting the ability of non-nested classes to infer from the base class;

In C ++, private: virtual makes sense because it means: "I want the classes received from me to redefine the functionality of this function, but they should not call it directly," in other words, private controls that can call a function and does not affect who can override it.

I understand that since only derived classes can be overridden in the first place, and since C # forbids private virtual functions, this question may be pointless if there are other scenarios in which the level of protection of the function can affect that can override it ( protected internal possible )?

+6
c ++ private c # language-design
source share
1 answer

It looks like you want the C ++ world to be able to override, but not invoke; then no: you cannot do this in C #. However, vice versa - either do not mark it virtual in the first place, or mark it sealed if it is already virtual .

+7
source share

All Articles