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
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. storage of employee objects in a container

storage of employee objects in a container

Scheduled Pinned Locked Moved ATL / WTL / STL
graphicsdockerdata-structuresjsonhelp
6 Posts 3 Posters 0 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.
  • T Offline
    T Offline
    The Bat Man
    wrote on last edited by
    #1

    I want to store a group of employee objects in an array or collection of some type and then be able to find which employees are of a certain department number. For example there may be a total of 10 employees with 4 of the employees belonging to department 1 and the rest to various other departments, I want to be able to find all of the employees belonging to department 1 and print those out. What do you think is the best way to do this? I tried to use a vector sequence container, but I don't know how I would find multiple employee objects depending on dept number attribute. Any help would be greatly appreciated, Jason

    S K 2 Replies Last reply
    0
    • T The Bat Man

      I want to store a group of employee objects in an array or collection of some type and then be able to find which employees are of a certain department number. For example there may be a total of 10 employees with 4 of the employees belonging to department 1 and the rest to various other departments, I want to be able to find all of the employees belonging to department 1 and print those out. What do you think is the best way to do this? I tried to use a vector sequence container, but I don't know how I would find multiple employee objects depending on dept number attribute. Any help would be greatly appreciated, Jason

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      You could have a map containing vectors. The map key would be the department number, and the data would be a vector (or better, a pointer to a vector) of employees.

      Steve S Developer for hire

      T 1 Reply Last reply
      0
      • S Steve S

        You could have a map containing vectors. The map key would be the department number, and the data would be a vector (or better, a pointer to a vector) of employees.

        Steve S Developer for hire

        T Offline
        T Offline
        The Bat Man
        wrote on last edited by
        #3

        But what if there were multiple map key's (department number's) that are the same? It would only show the first occurance, right? Is there a way I can show all objects of that same key? Thanks, Jason

        S 1 Reply Last reply
        0
        • T The Bat Man

          I want to store a group of employee objects in an array or collection of some type and then be able to find which employees are of a certain department number. For example there may be a total of 10 employees with 4 of the employees belonging to department 1 and the rest to various other departments, I want to be able to find all of the employees belonging to department 1 and print those out. What do you think is the best way to do this? I tried to use a vector sequence container, but I don't know how I would find multiple employee objects depending on dept number attribute. Any help would be greatly appreciated, Jason

          K Offline
          K Offline
          kalkwarf
          wrote on last edited by
          #4

          A multimap will allow you to have multiple values per key. Dave

          1 Reply Last reply
          0
          • T The Bat Man

            But what if there were multiple map key's (department number's) that are the same? It would only show the first occurance, right? Is there a way I can show all objects of that same key? Thanks, Jason

            S Offline
            S Offline
            Steve S
            wrote on last edited by
            #5

            Do you mean that there are multiple departments with the same number, or that there are multiple employees in the same department? If the former, then you cannot use department number as a key, since you cannot be sure which distinct department you should be referring to. If the latter, that's why the data is a vector, so you can add multiple employees.

            Steve S Developer for hire

            T 1 Reply Last reply
            0
            • S Steve S

              Do you mean that there are multiple departments with the same number, or that there are multiple employees in the same department? If the former, then you cannot use department number as a key, since you cannot be sure which distinct department you should be referring to. If the latter, that's why the data is a vector, so you can add multiple employees.

              Steve S Developer for hire

              T Offline
              T Offline
              The Bat Man
              wrote on last edited by
              #6

              The latter, multiple employees in the same department. How would I use a vector inside of a map? I tried the following example but received an error C2665 'std::pair<_Ty1,_Ty2>::__ctor' : none of the 3 overloads can convert parameter 2 from type 'const char [5]' typedef map > EmployeeType; void MapVectorTest() { EmployeeType theMap; EmployeeType::iterator theIterator; theMap.insert(EmployeeType::value_type(0, "Zero")); // error C2665 } -- modified at 14:43 Friday 2nd March, 2007 Thanks, Jason -- modified at 14:48 Friday 2nd March, 2007

              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