Avoiding compiler issues with abs()

后端 未结 2 399
独厮守ぢ
独厮守ぢ 2020-12-15 09:06

When using the double variant of the std::abs() function without the std with g++ 4.6.1, no warning or error is given.



        
2条回答
  •  自闭症患者
    2020-12-15 09:14

    Be warned, you don't need to explicitly #include , does the damage as well (and maybe some other headers). Also, note that -Wall doesn't give you any warnings about it.

    #include 
    
    int main() {
      std::cout << abs(.5) << std::endl;
      std::cout << typeid(decltype(abs)).name() << std::endl;
    }
    

    Gives output

    0
    FiiE
    

    On

    gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04) 
    

提交回复
热议问题