STLlimits
を使用して、与えている構造体の最小値、最大値、および無限大(これらのみだと思います)の値を決定するデータ構造を使用しています。このような実装固有の詳細がある場合、私は 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
}
numeric_limits
コピー アンド ペーストの力を借りて、必要と思われる 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>
そして、これらの宣言を確実に取得できるように、この後にヘッダーを含めます。ここでエラーが発生します:
namespace detail {
template<typename coordinate_type, bool is_integer, bool has_infinity>
struct coordinate_limits_impl;
template<typename coordinate_type>
struct coordinate_limits_impl<coordinate_type, true, false> {
static const coordinate_type highest() {
return std::numeric_limits<coordinate_type>::max(); // --- error here ---
}
static const coordinate_type lowest() {
return std::numeric_limits<coordinate_type>::min();
}
};
//lots of stuff
}
coordinate_type
の typedef ですPseudoTuple::ReturnWrapper
。エラーは次のとおりです。
error C2589: '(' : illegal token on right side of '::'
error C2059: syntax error : '::'
また、 と のすべての使用でこの興味深い警告が表示されますmin
。max
これはエラーと同じ行にあります。
warning C4003: not enough actual parameters for macro 'max'
このデータ構造をstd::array
ofstd::string
で使用すると、これらの警告は表示されますが、コンパイラ エラーは表示されません。その場合も適切に動作するため、全体が何らかの形で機能する必要があります。max
しかし、私のカスタムを使用すると、関数が認識されませんnumeric_limits
。
を に変更するmax()
とinfinity()
、正常にコンパイルされ、 でエラーがスローされmin()
ます。名前min
とmax
はそれにいくらかの悲しみを与えていますが、その理由はわかりません. infinity
ただし、これは、の実装からメソッドを取得できることを示してnumeric_limits
います。
編集: 適切な型が渡されていることを示すデータ構造コードを削除しましたが、無関係のようです。
編集 2: マーク B は問題を解決しましたが、新しい問題が発生しました:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: static struct PseudoTuple::ReturnWrapper __cdecl std::numeric_limits<struct PseudoTuple::ReturnWrapper>::max(void)" (__imp_?max@?$numeric_limits@UReturnWrapper@PseudoTuple@@@std@@SA?AUReturnWrapper@PseudoTuple@@XZ) referenced in function "public: static struct PseudoTuple::ReturnWrapper const __cdecl kd_v1_0_8::spatial::detail::coordinate_limits_impl<struct PseudoTuple::ReturnWrapper,1,0>::highest(void)" (?highest@?$coordinate_limits_impl@UReturnWrapper@PseudoTuple@@$00$0A@@detail@spatial@kd_v1_0_8@@SA?BUReturnWrapper@PseudoTuple@@XZ)
そのため、何かがリンクを台無しにしています... については同じですmin
が、については取得していませんinfinity
。