开始定义结构体如:
typedef struct student
{
id;
char name[20];
char sex[20];
char birthday[50];
score;
char description[100];
void* pWnd;
}STUDENT,*PSTUDENT;
定义个deque来保存这个结构体对象 deque<STUDENT>m_vecst; 现在我有个结构体对象想查找是否在这个deque中我开始是这样做:
STUDENT TT;
deque<STUDENT>::iterator iter = find(m_vecst.begin,m_vecst.end,TT);
( iter != m_vecst.end)
{
STUDENT DD = (STUDENT)(*iter);
char* name = DD.name;
}
但是编译不过去报为:
**********\\algorithm(43) : error C2678: binary '' : no operator d which takes a left-hand operand of type 'struct student' (or there is no acceptable conversion)
**********.cpp(549) : see reference to function template instantiation ' std::deque<struct student, std::allocator<struct student> >::iter
ator __cdecl std::find( std::deque<struct student, std::allocator<struct student> >::iterator, std::deque<struct student, std::allocator<struct student> >::iterator,const struct student &)' being compiled
Error executing cl.exe.
的所有这个主要是我们没有定义在查找结构体STUDENT时不知道如何样判断结构体是相等.因此我们必须重载结构体符号.如下:
typedef struct student
{
id;
char name[20];
char sex[20];
char birthday[50];
score;
char description[100];
void* pWnd;
bool operator (const student &A) const
{
(id A.id) true;
false;
}
}STUDENT,*PSTUDENT;
最新评论