Sort a std::list with myclass::operator<(myclass &other)

后端 未结 5 594
一生所求
一生所求 2021-01-12 04:31

I have a std::list and in my class I have myclass::operator<(myclass &other) defined.

I use the std::list.sort

5条回答
  •  悲哀的现实
    2021-01-12 05:30

    I was trying out the template PComp example and since other classes would be using the PComp I stuck in the the include file for the class the std::list was holding. However when I compiled the task I got this:

    In member function ‘EcTVoid FdFtTSBFDFTableLoadAppl::IngestTableProducts(const string&, const EcTInt&)’:
    /mms_builds/working/jkerich/MMS_SDF/sw/mms/dms/FdFtTSB/src/FdFtTSBFDFTableLoadAppl.C:782:53  error: no matching function for call to ‘std::list::sort()’
       myIngestedTables.sort(sorter.PComp); // sorted list
                                                         ^
    /mms_builds/working/jkerich/MMS_SDF/sw/mms/dms/FdFtTSB/src/FdFtTSBFDFTableLoadAppl.C:782:53  note: candidates are:
    In file included from /usr/include/c++/4.8.2/list:64:0,
                     from /mms_builds/working/jkerich/MMS_SDF/sw/mms/foscommon/common/FoCf/include/FoCfConfigSetup.h:11,
                     from /mms_builds/working/jkerich/MMS_SDF/sw/mms/foscommon/common/FoCf/include/FoCfTypes.h:156,
                     from /mms_builds/working/jkerich/MMS_SDF/sw/mms/dms/FdFtTSB/src/FdFtTSBFDFTableLoadAppl.C:18:
    /usr/include/c++/4.8.2/bits/list.tcc:353:5: note: void std::list<_Tp, _Alloc>::sort() [with _Tp = FoFmVirtualTbl*; _Alloc = std::allocator]
         list<_Tp, _Alloc>::
         ^
    /usr/include/c++/4.8.2/bits/list.tcc:353:5: note:   candidate expects 0 arguments, 1 provided
    /usr/include/c++/4.8.2/bits/list.tcc:430:7: note: void std::list<_Tp, _Alloc>::sort(_StrictWeakOrdering) [with _StrictWeakOrdering = bool (FoFmVirtualTbl::*)(const FoFmVirtualTbl* const&, const FoFmVirtualTbl* const&); _Tp = FoFmVirtualTbl*; _Alloc = std::allocator]
           list<_Tp, _Alloc>::
           ^
    /usr/include/c++/4.8.2/bits/list.tcc:430:7: note:   no known conversion for argument 1 from ‘’ to ‘bool (FoFmVirtualTbl::*)(const FoFmVirtualTbl* const&, const FoFmVirtualTbl* const&)’
    In file included from /ecs/MMS_SDF/RogueWave/13.2/dbg/rw/config/rwconfig_tls.h:9:0,
                     from /ecs/MMS_SDF/RogueWave/13.2/dbg/rw/compiler.h:5,
                     from /ecs/MMS_SDF/RogueWave/13.2/dbg/rw/defs.h:46,
                     from /ecs/MMS_SDF/RogueWave/13.2/dbg/rw/cstring.h:33,
                     from /mms_builds/working/jkerich/MMS_SDF/sw/mms/foscommon/common/FoCf/include/FoCfTypes.h:11,
                     from /mms_builds/working/jkerich/MMS_SDF/sw/mms/dms/FdFtTSB/src/FdFtTSBFDFTableLoadAppl.C:18:
    

    The template is this:

    template  bool PComp(const T * const & a, const T * const & b)
    {
        EcTInt status = a->compareTo(b);
        return ((status == -1) ? true : false);
    }
    

    the calls I tried in FdFtTSBFDFTableLoadAppl.C were:

    myIngestedTables.sort(PComp);   // sorted list
    

    or

    FoFmVirtualTbl sorter;
    myIngestedTables.sort(sorter.PComp);    // sorted lis
    

    t

    Only when the template was declared in FdFtTSBFDFTableLoadAppl did it compile ok. So how would I get this to compile if the template is in some others class include?

提交回复
热议问题