C++ Style: Prefixing virtual keyword to overridden methods

后端 未结 6 622
名媛妹妹
名媛妹妹 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条回答
  •  执念已碎
    2020-12-09 03:25

    Adding virtual does not have a significant impact either way. I tend to prefer it but it's really a subjective issue. However, if you make sure to use the override and sealed keywords in Visual C++, you'll gain a significant improvement in ability to catch errors at compile time.

    I include the following lines in my PCH:

    #if _MSC_VER >= 1400
    #define OVERRIDE override
    #define SEALED sealed
    #else
    #define OVERRIDE
    #define SEALED
    #endif
    

提交回复
热议问题