Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to find method of std::map?

Reply
Thread Tools

How to find method of std::map?

 
 
Allen
Guest
Posts: n/a
 
      01-07-2009
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
 
Reply With Quote
 
 
 
 
Allen
Guest
Posts: n/a
 
      01-07-2009
On Jan 7, 11:40*am, Allen <(E-Mail Removed)> wrote:
> 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?*
 
Reply With Quote
 
 
 
 
Allen
Guest
Posts: n/a
 
      01-07-2009
On Jan 7, 11:40*am, Allen <(E-Mail Removed)> wrote:
> 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!
 
Reply With Quote
 
Triple-DES
Guest
Posts: n/a
 
      01-07-2009
On 7 Jan, 04:40, Allen <(E-Mail Removed)> wrote:
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 3 02-14-2011 05:28 AM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
Re: Can't find elements using ElementTree find method Stefan Behnel Python 0 08-31-2010 09:00 AM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM



Advertisments