C++ 编译器无法识别自定义数字\u限制成员函数
我使用的数据结构希望使用STLC++ 编译器无法识别自定义数字\u限制成员函数,c++,templates,stl,compiler-errors,numeric-limits,C++,Templates,Stl,Compiler Errors,Numeric Limits,我使用的数据结构希望使用STLlimits来确定给定结构的最小值、最大值和无穷大值(我认为只有这些值)。我使用Visual C++ 2010,如果有实现这方面的具体细节。 以下是我的数据类型的基本结构,PseudoTuple::ReturnWrapper是需要限制支持的类型: struct PseudoTuple { struct ReturnWrapper { //wraps return values for comparisons and such } typedef Ret
limits
来确定给定结构的最小值、最大值和无穷大值(我认为只有这些值)。我使用Visual C++ 2010,如果有实现这方面的具体细节。
以下是我的数据类型的基本结构,PseudoTuple::ReturnWrapper
是需要限制支持的类型:
struct PseudoTuple
{
struct ReturnWrapper
{
//wraps return values for comparisons and such
}
typedef ReturnWrapper value_type;
//basic "tuple" implementation as a data front
}
利用复制和粘贴的功能,我为它创建了一个小的数值限制
类,只实现了我认为需要的3个函数。返回值当前是临时的,只是为了看看是否可以编译
namespace std
{
template<> class _CRTIMP2_PURE numeric_limits<PseudoTuple::ReturnWrapper>
: public _Num_int_base
{
public:
typedef PseudoTuple::ReturnWrapper _Ty;
static _Ty (__CRTDECL min)() _THROW0()
{ // return minimum value
return PseudoTuple::ReturnWrapper();
}
static _Ty (__CRTDECL max)() _THROW0()
{ // return maximum value
return PseudoTuple::ReturnWrapper();
}
static _Ty __CRTDECL infinity() _THROW0()
{ // return positive infinity
return PseudoTuple::ReturnWrapper();
}
};
}
#include <data structure using PseudoTuple>
并且在所有使用min
和max
的情况下都会得到这条有趣的警告,这条警告与错误位于同一行:
error C2589: '(' : illegal token on right side of '::'
error C2059: syntax error : '::'
warning C4003: not enough actual parameters for macro 'max'
当我将此数据结构与std::string
的std::array
一起使用时,仍然会收到这些警告,但不会弹出编译器错误。在这种情况下,它也可以正常运行,因此整个过程必须以某种方式工作。但在使用我的自定义数值限制时,它无法识别max
函数
如果我将max()
更改为infinity()
,它编译得很好,然后在min()
上抛出一个错误。名字min
和max
让它有些悲伤,但我不知道为什么。这确实告诉我,它可以从我实现的数值限制
中获取无穷
方法
编辑:删除的数据结构代码显示正在传入正确的类型,似乎与此无关
编辑2:Mark B解决了问题,但出现了一个新问题:
错误LNK2019:未解析的外部符号“\uu declspec(dllimport)public:static struct PseudoTuple::ReturnWrapper\uu cdecl std::numeric\u limits::max(void)”(\uu imp\ux max@?$numeric_limits@UReturnWrapper@伪元组@@std@@SA?AUReturnWrapper@PseudoTuple@@XZ)在函数中引用“public:static struct PseudoTuple::ReturnWrapper const_ucdecl kd_v1_0_8::space::detail::coordinate_limits_impl::highest(void)”(?highest@?$coordinate_limits)_impl@UReturnWrapper@伪元组@@@00$0A@@detail@spatial@kd_v1_0_8@@SA?BUReturnWrapper@PseudoTuple@@XZ)
所以有些东西把链接搞得一团糟,min
也一样,但infinity
有时min
和max
都是作为宏来实现的,它们只是替换文本。这里的问题不是你的特长,而是宏。我相信windows.h
就是这样的一个例子nder.你可以使用#define NOMINMAX
使它们不被创建为宏。有时min
和max
被实现为只替换文本的宏。在这里引起问题的不是你的专业化,而是宏。我相信windows.h
就是这样一个罪犯。你可以使用\define NOMINMAX
使它们不被创建为宏。可能重复Nice调用的可能重复,但显然我的专业化并不令人惊讶。现在出现链接器错误。粘贴到此框太长了,我已将其编辑到上述操作的结尾。不错的调用,但显然我的专业化并不令人惊讶。Ge现在正在设置链接器错误。粘贴到此框太长,我已将其编辑到上面OP的末尾。
warning C4003: not enough actual parameters for macro 'max'