Justification for forcing 'virtual' for overridden virtual functions

Since C++ does not force a programmer to specify the 'virtual' keyword when overriding a virtual function in a base class, what was the justification for forcing not only 'virtual' but also an after the parameter list 'override' when overriding virtual functions of a base ref class or interface class. For normal C++ programmers this bifurcation from C++ seems both a PITA and absolutely unnecessary. There must have been some practical reason for this top-heavy syntax, other than to add syntax just for the sake of orthogonality with 'virtual' / 'new' or just 'new', but I fail to see it. Obvious to me, having the same signature in a derived class as a virtual function in a base class should have automatically defaulted to 'virtual' and 'override', just like it does in standard C++, and then if someone wanted something different they could have used the 'virtual / 'new' or 'new' additions which MS added for C++/CLI. I find it really stupid that I now have to litter C++/CLI code with 'virtual' and 'override' to do something which in standard C++ does not demand this sort of overkill, as if I were some child and had to be taught C++ again in some babyish way..


Answer this question

Justification for forcing 'virtual' for overridden virtual functions

  • TylEray

    I agree: I hate this too. To be forced to provide the override keyword for the "normal" derivation process was bad design! Yes the defualt should be virtual and override like the normal C++ works!

    The practical reason is, that the CLI allows to override a virtual function or to declare a new function with the same. C++ never allowed this!

    Place a suggestion in

    http://lab.msdn.microsoft.com/productfeedback/Default.aspx



  • rd2h

    I think the decision of enforcing "virtual" or "override" in C++ was not made to help/bother the program writer, but to help the reader.

    If you ever looked at some C++ code you don't know with a poor IDE or a simple text editor (such as Network Simulator 2.26 with Anjuta), lacking the "virtual" keywords for virtual functions IS a PITA, while putting them when writing the code is not.

    In C++/CLI, you have the "override" keyword, that allows you to know that the virtual function was declared in a base class. So why do you whine Try to read some unknown ravioli C++ code and you will curse its author for forgetting to put "virtual".


  • karnayanar

    eldiener wrote:
    I placed it as a suggestion.

    Placve a link to here. I would vote for it!



  • stubs

    I placed it as a suggestion.

  • Lance P. Smith

    I should point out that the ISO/IEC C++ committee is considering allowing something very similar to what is in C++/CLI.

  • RickBoogher

    If and when they change I will be glad to change, even if I disagree with the redundancy, but why force such a change on programmers, especially as VC++ could have allowed what they have enforced while still tolerating the normal C++ way of overriding virtual functions. Furthermore I do not believe that the ISO/IEC C++ committee will force both a redundant 'virtual' and an 'override' for overriding virtual functions in a derived class.

  • Large_Goose

    The link is http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx feedbackid=bf3424ab-33d8-448d-a331-d80d609f0b66 .

  • Justification for forcing 'virtual' for overridden virtual functions