在重新安装Rad-Studio XE2之后,我发现一些用于编译的代码不再起作用。例如,我在以下方面得到了一个编译器错误:
#include <cmath>
void MyClass::Rotate(double RotAngle){
bool NotRotated = std::abs(RotAngle) < 1;
... do something
}有以下错误:
[BCC32 Error] XXX.cpp(38): E2015 Ambiguity between 'std::abs(int) at c:\program files (x86)\embarcadero\rad studio\9.0\include\windows\crtl\stdlib.h:142' and 'std::abs(__int64) at c:\program files (x86)\embarcadero\rad studio\9.0\include\windows\crtl\stdlib.h:538'这段代码过去是编译的,显然应该编译,那么我遗漏了什么呢?Rad_studio已经应用了所有的更新。
发布于 2013-11-25 17:39:05
在这种情况下,我们实际上可以从标准中学到很多东西。
C++98:在26.5/表80和81中,我们了解到abs在<cstdlib>中,而不是<cmath>中。但是在26.5中,我们有一个自相矛盾的语句In addition to the double versions of the math functions in <cmath>, C++ adds float and long double overloaded versions of these functions, with the same semantics.,其中列出了abs在<cmath>中有额外的重载,而前面的表说它不应该是这样的。
实际上,这在C++11中是固定的,其中26.8/表119清楚地显示abs是<cmath>的成员,也是<cstdlib>的成员(尽管为浮点类型添加的重载仍然是<cmath>独有的。
至于您的问题,有两种可能的情况:
<cmath>不再隐式包含<cstdlib>的版本,您的编译器基于表需求而不是26.5的隐式需求。很可能包括<cstdlib>将修复这个问题,就像在C++11模式下编译一样。
https://stackoverflow.com/questions/20199043
复制相似问题