2012-09-26 2 views
1

STL limits을 사용하려는 데이터 구조를 사용하여 구조체의 최소, 최대 및 무한대를 결정했습니다. 이 항목에 대한 구현 세부 정보가 있으면 Visual C++ 2010을 사용하고 있습니다.컴파일러가 사용자 정의 numeric_limits 멤버 함수를 인식하지 못합니다.

여기 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를 구현, 그것을 위해 작은 numeric_limits 클래스를 생성 기능이 필요하다고 생각합니다. 반환 값은 현재 일시적이며, 이것이 컴파일되는지를보기 위해서입니다.

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_typePseudoTuple::ReturnWrapper의 형식 정의입니다. 여기서 오류는 다음과 같습니다

error C2589: '(' : illegal token on right side of '::' 
error C2059: syntax error : '::' 

또한 minmax 오류와 같은 줄에있는이 일의 모든 사용에 대한 흥미로운 경고를 받고 :

warning C4003: not enough actual parameters for macro 'max' 

나는이 데이터 구조를 사용하는 경우 std::arraystd::string인데도 여전히 경고가 표시되지만 컴파일러 오류는 표시되지 않습니다. 이 경우에도 제대로 작동하므로 모든 것이 어떻게 든 작동해야합니다. 그러나 내 맞춤형 numeric_limits을 사용할 때 max 기능을 인식하지 못합니다.

max()infinity()으로 변경하면 정상적으로 컴파일되고 min()에 오류가 발생합니다. minmax이라는 이름은 약간의 슬픔을주고 있지만 왜 그런지는 잘 모르겠습니다. 이것은 numeric_limits의 구현에서 infinity 메서드를 가져올 수 있다고 말해줍니다.

편집 : 올바른 유형이 전달되고 있음을 보여주는 제거 된 데이터 구조 코드가 관련성이없는 것처럼 보입니다.

편집 2 : 마크 B는 문제를 해결하지만, 새로운 하나의 팝업 :

error LNK2019: unresolved external symbol "__declspec(dllimport) public: static struct PseudoTuple::ReturnWrapper __cdecl std::numeric_limits<struct PseudoTuple::ReturnWrapper>::max(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]@@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)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@XZ)

그래서 뭔가 infinity에 대한 min에 대해 동일한 얻기하지만 ... 링킹을 엉망입니다.

+1

[가능한 방법은 windows.h의'max' 매크로를'std'에서'max'와 충돌시키는 것입니까?] (http://stackoverflow.com/questions/11544073/how-do-i) -deal-with-the-max-macro-in-windows-h-colliding-with-max-in-std) –

답변

1

때로는 minmax이 텍스트를 대체하는 매크로로 구현되었습니다. 여기에 문제를 야기하는 것은 전문 분야가 아니라 매크로입니다. 나는 windows.h이 그러한 범죄자 중 하나라고 믿습니다. #define NOMINMAX을 사용하면 해당 매크로를 매크로로 만들 수 없습니다.

+0

전화는 좋지만 외관상으로는 너무 전문적이지 않습니다. 링커 오류가 발생했습니다. 이 상자에 붙여 넣기에는 너무 길어서 위의 OP 끝까지 편집했습니다. – user173342