How to find method of std::map?

A

Allen

struct FcdaCompare
{
bool operator()(const SclNode* n1, const SclNode* n2) const
{
return n1 < n2;
}
};

std::map< const SclNode*, const DataSetFcda*, FcdaCompare > fcdaMap;

I want to find an entry this way

SclNode * pNode = ...;
std::map< const SclNode*, const DataSetFcda*, FcdaCompare >::iterator
itr = fcdaMap.find(pNode); /* find line */
....

But compiling fails at *find line*.
Where is the problem? Please help me.
Thank you.

Allen
 
A

Allen

struct FcdaCompare
{
        bool operator()(const SclNode* n1, const SclNode* n2) const
        {
                return n1 < n2;
        }

};

std::map< const SclNode*, const DataSetFcda*, FcdaCompare > fcdaMap;

I want to find an entry this way

SclNode * pNode = ...;
std::map< const SclNode*, const DataSetFcda*, FcdaCompare >::iterator
itr = fcdaMap.find(pNode); /* find line */
...

But compiling fails at *find line*.
Where is the problem? Please help me.
Thank you.

Allen

So bad, the title should be *How to use find method of std::map?*
 
A

Allen

struct FcdaCompare
{
        bool operator()(const SclNode* n1, const SclNode* n2) const
        {
                return n1 < n2;
        }

};

std::map< const SclNode*, const DataSetFcda*, FcdaCompare > fcdaMap;

I want to find an entry this way

SclNode * pNode = ...;
std::map< const SclNode*, const DataSetFcda*, FcdaCompare >::iterator
itr = fcdaMap.find(pNode); /* find line */
...

But compiling fails at *find line*.
Where is the problem? Please help me.
Thank you.

Allen

I am so stupid. I code *find line* like this.
std::map< const SclNode*, const DataSetFcda*, FcdaCompare > itr =
fcdaMap.find(pNode);
I feel so sorry!
 
T

Triple-DES

struct FcdaCompare
{
        bool operator()(const SclNode* n1, const SclNode* n2) const
        {
                return n1 < n2;
        }

};

This is not a very good idea, because unless n1 and n2 points to
members of the same object or array, the result of this comparison is
unspecified. Did you really intend to compare the pointer values? If
so, you must use
std::map< const SclNode*, const DataSetFcda* >
instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top