Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. a question about STL sort

a question about STL sort

Scheduled Pinned Locked Moved ATL / WTL / STL
questionc++tutorial
3 Posts 3 Posters 20 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    liuty2006
    wrote on last edited by
    #1

    struct A{ public: CString str1; CString str2; COleDateTimeSpan vdTime; long nNum; }; typedef std::list aList; ......//add some A Type to aList can i sort the 'aList' by the nNum? How to do with it?

    J C 2 Replies Last reply
    0
    • L liuty2006

      struct A{ public: CString str1; CString str2; COleDateTimeSpan vdTime; long nNum; }; typedef std::list aList; ......//add some A Type to aList can i sort the 'aList' by the nNum? How to do with it?

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      Add a suitable comparison operator to A:

      struct A
      {
      ...
      bool operator<(const A& r) const
      {
      return nNum<r.nNum;
      }
      }

      and then just use std::list::sort. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      • L liuty2006

        struct A{ public: CString str1; CString str2; COleDateTimeSpan vdTime; long nNum; }; typedef std::list aList; ......//add some A Type to aList can i sort the 'aList' by the nNum? How to do with it?

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        I cover this at length in my article on functors. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups