C++ Style: Prefixing virtual keyword to overridden methods

后端 未结 6 634
名媛妹妹
名媛妹妹 2020-12-09 03:15

I\'ve been having a discussion with my coworkers as to whether to prefix overridden methods with the virtual keyword, or only at the originating base class.

I tend t

6条回答
  •  旧时难觅i
    2020-12-09 03:41

    I would tend not to use any syntax that the compiler will allow me to omit. Having said that, part of the design of C# (in an attempt to improve over C++) was to require overrides of virtual methods to be labeled as "override", and that seems to be a reasonable idea. My concern is that, since it's completely optional, it's only a matter of time before someone omits it, and by then you'll have gotten into the habit of expecting overrides to be have "virtual" specified. Maybe it's best to just live within the limitations of the language, then.

提交回复
热议问题