我正在尝试使用多键结构作为键来创建多映射,但出现以下错误:
代码:
struct stCont
{
long long Tok;
char Reserved;
long long Asset;
}
struct MultiKey {
char InstrumentName[6];
char Symbol[10];
long long ExpiryDate;
}
std::multimap<MultiKey, stCont> cont_map;
错误:
C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xfunctional:125: error: C2678: binary '<' : no operator found which takes a left-hand operand of type 'const MultiKey' (or there is no acceptable conversion)
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore/qchar.h(391): could be 'bool operator <(QChar,QChar)' [found using argument-dependent lookup]
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore/qbytearray.h(538): or 'bool operator <(const QByteArray &,const QByteArray &)' [found using argument-dependent lookup]
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore/qbytearray.h(540): or 'bool operator <(const QByteArray &,const char *)' [found using argument-dependent lookup]
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore/qbytearray.h(542): or 'bool operator <(const char *,const QByteArray &)' [found using argument-dependent lookup]
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore/qstring.h(565): or 'bool operator <(const QString &,const QString &)' [found using argument-dependent lookup]
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore/qstring.h(625): or 'bool operator <(const char *,const QString &)' [found using argument-dependent lookup]
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore/qstring.h(632): or 'bool operator <(const char *,const QStringRef &)' [found using argument-dependent lookup]
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore/qstring.h(975): or 'bool operator <(QLatin1String,QLatin1String)' [found using argument-dependent lookup]
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore/qstring.h(1032): or 'bool operator <(const char *,QLatin1String)' [found using argument-dependent lookup]
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore/qstring.h(1304): or 'bool operator <(const QStringRef &,const QStringRef &)' [found using argument-dependent lookup]
while trying to match the argument list '(const MultiKey, const MultiKey)'
我为 myComp 编写了这段代码:
struct myComp
{
bool operator() (const MultiKey& lhs, const MultiKey& rhs)
{
if((lhs.ExpiryDate==rhs.ExpiryDate)&&(memcmp(lhs.InstrumentName,rhs.InstrumentName,6))&&(memcmp(lhs.Symbol,rhs.Symbol,10)))
{
return 1;
}
return 0;
}
};
现在我得到一个错误:
C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xtree:1546: error: C3848: expression having type 'const myComp' would lose some const-volatile qualifiers in order to call 'bool myComp::operator ()(const MultiKey &,const MultiKey &)'