Re: How to find method of std::map?
Allen <Allen.Chenal@gmail.com> wrote:
On Jan 7, 11:40?am, Allen <Allen.Che...@gmail.com> 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?*
So bad is that you didn't provide enough information. A compilable
example would help. Also, and explaination of what you mean by "failed",
did it fail to compile, or fail to link, or fail to find the object?
The following works fine:
#include <map>
class SclNode { };
class DataSetFcda { };
struct FcdaCompare {
bool operator()(const SclNode* n1, const SclNode* n2) const {
return n1 < n2;
}
};
typedef std::map< const SclNode*, const DataSetFcda*, FcdaCompare >
FcdaMap;
int main() {
FcdaMap fcdaMap;
fcdaMap[0] = 0;
SclNode * pNode = 0;
FcdaMap::iterator itr = fcdaMap.find(pNode);
assert( itr != fcdaMap.end() );
assert( itr->first == 0 );
assert( itr->second == 0 );
}
--
Perfection is achieved, not when there is nothing more to add,
but when there is nothing left to take away.
-- Antoine de Saint-Exupery