我已经与运营商<以下数据来实现:std :: set - 实现operator <?的正确方法?
enum eDataSetType
{
eData1,
eData2
};
struct LocationData
{
bool operator < (const LocationData& other) const
{
if (mFileName < other.mFileName ||
mDataSet < other.mDataSet ||
mChunkId < other.mChunkId ||
mAnimIndex < other.mAnimIndex)
{
return true;
}
return false;
}
eDataSetType mDataSet;
std::string mFileName;
Uint32 mChunkId;
Uint32 mAnimIndex;
};
但使用std::set<LocationData>::insert
我有时会收到以下消息时:
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Assertion Failed!
Program: C:\Windows\system32\MSVCP120D.dll
File: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree
Line: 1795
Expression: invalid operator<
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
---------------------------
为什么?
因为您没有创建正确的排序。 –
您的运营商未定义订购。这是垃圾。你想如何订购物品? –
E.g.在你的逻辑中,'(1,0)<(0,1)'和'(0,1)<(1,0)'是真的。 –