Newbie: STL Map Container find method functioN

L

lakepeir

Hello,

I'm having problems with the find function of the STL map structure.
Whenever I call the find method with an ID, the else is executed as if
the value exist in the map. The ID does not exist in the map because I
haven't added it.

Here's the Code:
std::map<CComVariant, CComPtr<Interface> > mymap;
DWORD ID;

if( mymap.find(ID) == mymap.end() )
{
//do something
}
else
{
//do something
}

Any help is appreciated. Thanks.
 
T

TB

(e-mail address removed) skrev:
Hello,

I'm having problems with the find function of the STL map structure.
Whenever I call the find method with an ID, the else is executed as if
the value exist in the map. The ID does not exist in the map because I
haven't added it.

Here's the Code:
std::map<CComVariant, CComPtr<Interface> > mymap;
DWORD ID;

Maybe you should initialize 'ID'.
if( mymap.find(ID) == mymap.end() )
{
//do something
}
else
{
//do something
}

Any help is appreciated. Thanks.

How does CComVariant perform equality testing?
 
R

Richard Herring

TB said:
(e-mail address removed) skrev:

Maybe you should initialize 'ID'.


How does CComVariant perform equality testing?

Almost but not quite. The relevant question (for std::map) is
"how does CComVariant perform less-than comparisons?" If that isn't a
strict weak ordering, none of std::map's operations will work properly.

Also, how does DWORD get converted to CComVariant? The argument to
map::find should be a (const reference to) key_value, which is
CComVariant, not DWORD.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top