On Apr 10, 2:50 pm, rpbg...@yahoo.com (Roland Pibinger) wrote:
> On Tue, 10 Apr 2007 19:47:25 +0200, Obnoxious User wrote:
> >With pointers as keys, it will by default sort using pointer addresses.
>
> ... because STL was designed only for values. For pointers you need
> workarounds.
>
> >Add your own sorting functor to sort it the way you want.
>
> >struct my_sort {
> > bool operator()(BOMBImntRT * a, BOMBImntRT * b) {
>
> bool operator()(const BOMBImntRT * a, const BOMBImntRT * b) const {
>
> > return a->some_value < b->some_value;
> > }
> >};
>
> >std::multimap<BOMBImntRT*, BOMBPortfolio*, my_sort> undPortMap;
Thanks for the reply
A stupid question ... why are we overloading opeartor ()?
struct UnderlyingsPtrSorter
{
bool operator() (BOMBImntRT* a, BOMBImntRT* b){
return a->ImntName < b->ImntName;
}
};
std::multimap<BOMBImntRT*, BOMBPortfolio*, UnderlyingsPtrSorter>
undPortMap;
std::multimap<BOMBImntRT*, BOMBPosition*, UnderlyingsPtrSorter>
undPosMap;
std::multimap<BOMBImntRT*, BOMBPortfolio*,
UnderlyingsPtrSorter> ::iterator undPortIt;
std::multimap<BOMBImntRT*, BOMBPosition*,
UnderlyingsPtrSorter> ::iterator undPosIt;
I'm getting these compiling errors:
c:\program files\microsoft visual studio enterprise edition
\vc98\include\xtree(51

: error C2662: '()' : cannot convert 'this'
pointer from 'const struct UnderlyingsPtrSorter' to 'struct
UnderlyingsPtrSorter &'
Conversion loses qualifiers
c:\program files\microsoft visual studio enterprise edition
\vc98\include\xtree(514) : while compiling class-template member
function 'struct std::_Tree<class BOMBImntRT *,struct std:

air<class
BOMBImntRT * const,class BOMBPosition *>,struct
std::multimap<class BOMBImntRT *,class BOMBPosition *,struct
UnderlyingsPtrSorter,class std::allocator<class BOMBPosition *>
>::_Kfn,struct UnderlyingsPtrSorter,class std::allocator<class
BOMBPosition *> >::_Node *__thiscall std::_Tree<class BOMBIm
ntRT *,struct std:

air<class BOMBImntRT * const,class BOMBPosition
*>,struct std::multimap<class BOMBImntRT *,class BOMBPosition *,struct
UnderlyingsPtrSorter,class std::allocator<class BOMBPosition *>
>::_Kfn,struct UnderlyingsPtrSorter,class std:
:allocator<class BOMBPosition *> >::_Lbound(class BOMBImntRT *const
& ) const'
c:\program files\microsoft visual studio enterprise edition
\vc98\include\xtree(51

: error C2064: term does not evaluate to a
function
c:\program files\microsoft visual studio enterprise edition
\vc98\include\xtree(514) : while compiling class-template member
function 'struct std::_Tree<class BOMBImntRT *,struct std:

air<class
BOMBImntRT * const,class BOMBPosition *>,struct
std::multimap<class BOMBImntRT *,class BOMBPosition *,struct
UnderlyingsPtrSorter,class std::allocator<class BOMBPosition *>
>::_Kfn,struct UnderlyingsPtrSorter,class std::allocator<class
BOMBPosition *> >::_Node *__thiscall std::_Tree<class BOMBIm
ntRT *,struct std:

air<class BOMBImntRT * const,class BOMBPosition
*>,struct std::multimap<class BOMBImntRT *,class BOMBPosition *,struct
UnderlyingsPtrSorter,class std::allocator<class BOMBPosition *>
>::_Kfn,struct UnderlyingsPtrSorter,class std:
:allocator<class BOMBPosition *> >::_Lbound(class BOMBImntRT *const
& ) const'
Error executing cl.exe.