2012-09-22 21 views
1

我想映射::插入一個關鍵的數據類型我定義(miniVec2ui)..它在比較期間(比較時它有假數據)中斷。它使用標準更少的函數(我試着用我自己的,但同樣的問題) - 它傳遞rhs.x = ???和rhs.y = ???基本上。代碼如下C++運行時錯誤:運營商<接收rhs與??? value..Surely愚蠢的錯誤我失蹤

miniVec2ui v233 = miniVec2ui(x,y); 

m_pIdMap->insert(std::pair<miniVec2ui,uint>(v233,(uint)tmpPF.id));// std::pair<const miniVec2ui,uint>(v233, (uint)tmpPF.id)); 
//////in other files I defined miniVec2ui,etc. (uint = unsigned int), tmpPF.id unimportant here, uint x; uint y; 



typedef std::map<miniVec2ui,uint>  eIdMap; 
eIdMap *m_pIdMap; 
m_pIdMap =  new eIdMap;//new std::map<miniVec2ui, uint >; 
struct miniVec2ui { 
    uint x; 
    uint y; 
    miniVec2ui(uint inx, uint iny): 
       x(inx) 
       ,y(iny) { } 

    bool operator==(const miniVec2ui& rhs) const { 
     return ((x == rhs.x) && (y == rhs.y)); 
    } 
    bool operator!=(const miniVec2ui& rhs) const { 
     return ((x != rhs.x) || (y != rhs.y)); 
    } 

    bool operator< (const miniVec2ui& rhs) const { 
     return ((x < rhs.x) && (y < rhs.y)); 

    } 
    bool operator> (const miniVec2ui& rhs) const { 
     return ((x > rhs.x) && (y > rhs.y)); 
    } 

}; 

具體 - 打破與__y _function_base.h是{X = ???,Y = ???} ...這裏的拆解:

...stuff... 
#endif 

{ 
    bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; } 
200439C0 55     push  ebp 
200439C1 8B EC    mov   ebp,esp 
200439C3 81 EC CC 00 00 00 sub   esp,0CCh 
200439C9 53     push  ebx 
200439CA 56     push  esi 
200439CB 57     push  edi 
200439CC 51     push  ecx 
200439CD 8D BD 34 FF FF FF lea   edi,[ebp-0CCh] 
200439D3 B9 33 00 00 00  mov   ecx,33h 
200439D8 B8 CC CC CC CC  mov   eax,0CCCCCCCCh 
200439DD F3 AB    rep stos dword ptr es:[edi] 
200439DF 59     pop   ecx 
200439E0 89 4D F8    mov   dword ptr [ebp-8],ecx 
200439E3 8B 45 0C    mov   eax,dword ptr [__y] 
200439E6 50     push  eax 
200439E7 8B 4D 08    mov   ecx,dword ptr [__x] 
200439EA E8 67 84 F1 FF  call  miniVec2ui::operator< (1FF5BE56h) 
200439EF 5F     pop   edi <--------------------- HERE ---------- << 
+1

請從您的帖子中刪除可愛和賄賂,這是分心。 –

+1

每次編輯20分鐘後不要編譯。爲你維護的類製作一個小程序(稱爲單元測試)並編譯和調試測試。只有在測試顯示班級做了你想做的事時,才編譯整個應用程序。 –

+0

班的測試案例:我應該,Oo Tiib。林德:不要回答,如果它分心,口授味道更糟。 – SinisterRainbow

回答

7

我有不知道,如果是涉及到你發現了錯誤,但你的小於比較應該實施strict weak ordering,它不:

bool operator< (const miniVec2ui& rhs) const { 
    return ((x < rhs.x) && (y < rhs.y)); 
} 

通過這種邏輯,m1不小於m2,並且m2不小於m1

miniVec2ui m1(5,5); 
miniVec2ui m2(6,5); 
std::cout << std::boolalpha; 
std::cout << m1 < m2 << "\n"; 
std::cout << m2 < m1 << "\n"; 

std::map使用該條件來確定兩個元素是否相等。你可能需要像

bool operator< (const miniVec2ui& rhs) const { 
    if (x == rhs.x) return y < rhs.y; 
    return x < rhs.x; 
} 

你應該嘗試實施operator>operator<operator!=方面在operator==條款。

+0

啊..缺少所有的測試案例..呃邏輯陰險。謝謝,和漂亮優雅的解決方案。 +1 ..這當然會解決問題。另外,我通常會這麼做,但是在實施運營商時得到投訴!=在運營商方面== .. ..而不是混淆它,這次只是寫了一些獨立軟件。速度是一個問題。我選擇了這個答案。感謝..火柴人noire射手隨機產生的cryengine世界如果感興趣..已經在(某種形式)兩個星期。讓我知道。 – SinisterRainbow