The following code:
#include <vector>
#include <algorithm>
struct myStructDim
{
int nId;
int dwHeight;
int dwWidth;
};
void main()
{
::std::vector<myStructDim> m_vec_dim;
::std::sort(m_vec_dim.begin(), m_vec_dim.end());
m_vec_dim.erase(
::std::unique(m_vec_dim.begin(), m_vec_dim.end()),
m_vec_dim.end()
);
}
will not compile with many errors, such as:
error C2784: ‘bool std::operator
==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)’ :
could not deduce template argument for
‘const std::vector<_Ty,_Alloc> &’ from
‘myStructDim’
I understand that I have to override an operator or two.
Which ones and how exactly please?
Thanks for the support!
You need comparison operators to express the “less-than” and “equality” relationships. Defining stand-alone boolean functions
operator<andoperator==that take two arguments, eachconst myStructDim&, and perform the comparison exactly the way you require, is probably simpler than defining then as methods within thestruct.