Hi everyone, I am still a relatively new programmer. I have used STL to some extent previously but my usage to maps has always been with using built-in types as the key.
Currently, I am tasked with doing something that I need to keep track of unique 2D data on a UV map. The generated coordinates may iterate over a 2D coordinate a few times but I only want to keep track of a single set of 2D data (therefore my choice of using map is correct?)
Anyway, here's some code for the experts here to digest.
In the header file...
In the CPP file...
typedef struct VECTOR2 : public D3DXVECTOR2
VECTOR2( float x, float y );
bool operator < ( CONST VECTOR2& ) const;
struct wave_compare : public std::binary_function<VECTOR2, VECTOR2, bool>
bool operator() (const VECTOR2& left, const VECTOR2& right) const
if( left.x < right.x || left.y < right.y )
typedef std::pair<VECTOR2,VECTOR2> wavePointPair;
typedef std::map<VECTOR2,VECTOR2,wave_compare> wavePointMap;
typedef std::map<VECTOR2,VECTOR2,wave_compare>::iterator wavePointMapIter;
Insertion into the map here like this...
CrsEffectTest :: VECTOR2 :: operator<( CONST VECTOR2 &right) const
if( x < right.x || y < right.y )
CrsEffectTest :: VECTOR2 :: VECTOR2( float xx, float yy )
x = xx;
y = yy;
I am getting errors at runtime
waveInfo.insert( wavePointPair( VECTOR2( vtx.x, vtx.y ), VECTOR2( vtx.u, vtx.v ) ) );
I presume that there is no 'correct' way to sort a 2D data but for me, I just want them to be easily reference with the find method to adjust the elements...
Assertion failed: invalid operator<
BTW, there is no error when && is used in the comparison above but that screws up the comparison and many 2D coordinates cannot be inserted because they are seen as non-unique?
Help! Thanks in advance.