为什么<T>编译器将 numeric_limits::min 解释为函数指针?
why is numeric_limits<T>::min being interpreted as a function pointer by compiler?
我正在使用模板编写一个浮点比较函数:
template<class T>
static bool AlmostEqual(T f1, T f2)
我有这样一个语句:
T min_value = std::numeric_limits<T>::min();
由于某种原因,编译器将上面的最小值视为函数指针并发出错误:
../include/CommonFunctions.h: In static member function ‘static bool CommonFunctions::AlmostEqual(T, T) [with T = double]’:
file.cpp:2200: instantiated from here
../include/CommonFunctions.h:22: error: cannot convert ‘double (*)()throw ()’ to ‘double’ in initialization
静态函数被定义为大程序的一部分。但是,当我将相同的函数放在一个独立的文件中并编译和使用它时,我没有看到任何错误。我读了其他人的帖子,试着这样做:
T min_value(std::numeric_limits<T>::min());
我仍然得到相同的错误,而且还有一个:
../include/CommonFunctions.h:22:53: error: macro "min" requires 2 arguments, but only 1 given
在一个错误中,它能够正确地将min解析为函数,而在另一个错误中,它被视为宏。我不确定如何解决这个问题。有什么建议吗?
对于包括windows.h在内的人,请在有效的头文件中放入以下内容:
#include windows headers ...
pragma push_macro("min")
pragma push_macro("max")
#undef min
#undef max
#include headers expecting std::min/std::max ...
...
pragma pop_macro("min")
pragma pop_macro("max")
在源文件中只需要#undef和max.
#include windows headers ...
#undef min
#undef max
#include headers expecting std::min/std::max ...
相关文章:
- 请解释"函数1(p1,p2,p3);"的输出
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 被解释为低级别const的const对象的地址
- 计算每个节点的树高,帮助我解释这个代码解决方案
- MSVC将仅移动结构参数解释为指针
- 内联程序集printf将整数解释为地址
- 有人能解释一下为什么下界是这样工作的吗C++的
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 我是c ++的新手,你能解释一下在这种情况下的指针吗
- 有人能为我解释一下C++代码吗
- 如何使用std::min和std::less返回对象
- 为什么 -mmacosx-version-min=10.10 不阻止使用标记为从 10.11 开始的函数?
- 关于 std::min, std::max 中的比较运算符的混淆
- 你能解释一下什么运行时错误是如何解决它的吗?
- 请解释字谜的代码,我看不懂计数器数组,每个值已经是0
- 有人可以向我解释为什么控制台输出 0 吗?
- 有人可以解释一下这段代码如何能够反转字符串
- 在 C++ 中解释多维向量的语句时感到困惑
- 为什么<T>编译器将 numeric_limits::min 解释为函数指针?
- std::min未能将枚举常量解释为有效的整数类型(g++4.6.3)