• Effective C++ 笔记 —— Item 53: Pay attention to compiler warnings.


    Many programmers routinely ignore compiler warnings. After all, if the problem were serious, it would be an error, right? This thinking may be relatively harmless in other languages, but in C++, it's a good bet compiler writers have a better grasp of what's going on than you do. For example, here's an error everybody makes at one time or another:

    class B 
    {
    public:
        virtual void f() const;
    };
    
    class D : public B 
    {
    public:
        virtual void f();
    };

    The idea is for D::f to redefine the virtual function B::f, but there's a mistake: in B, f is a const member function, but in D it's not declared const. One compiler I know says this about that:

    warning: D::f() hides virtual B::f()

    Too many inexperienced programmers respond to this message by saying to themselves, "Of course D::f hides B::f — that’s what it’s supposed to do!" Wrong. This compiler is trying to tell you that the f declared in B has not been redeclared in D; instead, it's been hidden entirely (see Item 33 for a description of why this is so).

    Things to Remember

    • Take compiler warnings seriously, and strive to compile warning free at the maximum warning level supported by your compilers.
    • Don't become dependent on compiler warnings, because different compilers warn about different things. Porting to a new compiler may eliminate warning messages you've come to rely on.
  • 相关阅读:
    层次遍历二叉树时的一个技巧
    合并两个有序链表
    关于指针的引用和“||”运算符的一些心得
    UE4中显示AI Debug信息
    EQS 自定义Context 如何用Testing Pawn 进行测试?
    4.16中Montage的一些变化
    Move Controller UE4键位
    EQS
    获取文件完整路径快捷方法
    同步引擎版本号的简易方法
  • 原文地址:https://www.cnblogs.com/zoneofmine/p/16010086.html
Copyright © 2020-2023  润新知