-
How CList Find struct
Hello ,
I try to find the structure which is in the clist [mfc]
Code:
Struct sentence
{
int id;
CString name;
};
CList<sentence>sentenceinfo ;
sentence sRec1;
sRec1.id = 10;
sRec1name = "LONG"
sentenceinfo.addTrail(sRec1);
sentence sRec2;
sRec1.id = 20;
sRec1name = "SHORT"
sentenceinfo.addTrail(sRec2);
here I want to check whether the id and name are existing in the structure.
sentence tmpRec:
tmpRec.id = 10;
tmpRec.name = "SHORT "
For example
Is it possible to check like this
If(sentenceinfo.Find(tmpRec ) == NULL)
sentenceinfo.AddTrail(tmpRec);
else
Already exist.
Since I don't have system I could not check and on the way to my office. If you could suggest me on this, It will be useful.
Thank you
-
-
Quote:
Originally Posted by
Salem
I can able to find the struct element.
what i did was
Code:
sentence tmpRec;
tmpRec.id = 10;
tmpRec.name = "LONG";
If(sentenceinfo.Find(tmpRec ) == NULL) sentenceinfo.AddTrail(tmpRec);
else
Already exist.
I need to include the comparison operator overloading in the structure.
struct sentence
{
int id;
CString name;
bool operator==(const sentence Scode) const
{
if (nId == Scode.nId && strName == Scode.strName)
return TRUE;
else
return NULL;
}
}
-
Thanks for your reply.I can also create the CList class.I feel like for my case, it is fine