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. C / C++ / MFC
  4. Dynamic memory

Dynamic memory

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformance
4 Posts 4 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.
  • B Offline
    B Offline
    bhangie
    wrote on last edited by
    #1

    Hi there Can anyone advise. I have a class called Employee ok. Now i want the user to create employees by adding a name, empid and so on. Creating an Employee object // Employee *NewEmp = new Emp ?? I want the new employees details in a file .dat it keeps on creating one employee overriding the previous info. How can i create more than one employee Hit me over the knuckles if im way of! Am i using new wrong? or am i missing the hole new concept totaly thanks:-D

    A B D 3 Replies Last reply
    0
    • B bhangie

      Hi there Can anyone advise. I have a class called Employee ok. Now i want the user to create employees by adding a name, empid and so on. Creating an Employee object // Employee *NewEmp = new Emp ?? I want the new employees details in a file .dat it keeps on creating one employee overriding the previous info. How can i create more than one employee Hit me over the knuckles if im way of! Am i using new wrong? or am i missing the hole new concept totaly thanks:-D

      A Offline
      A Offline
      Anthony_Yio
      wrote on last edited by
      #2

      if your class is written with contructor

      Employee::Employee(CString strName, int iAge)
      {
      this->m_strName = strName;
      this->m_iAge = iAge;
      }

      you probably could initiate your object as such

      Employee *pEmp = new Employee(_T("Someone"), 22);

      these are basic, man Sonork 100.41263:Anthony_Yio

      1 Reply Last reply
      0
      • B bhangie

        Hi there Can anyone advise. I have a class called Employee ok. Now i want the user to create employees by adding a name, empid and so on. Creating an Employee object // Employee *NewEmp = new Emp ?? I want the new employees details in a file .dat it keeps on creating one employee overriding the previous info. How can i create more than one employee Hit me over the knuckles if im way of! Am i using new wrong? or am i missing the hole new concept totaly thanks:-D

        B Offline
        B Offline
        BadJerry
        wrote on last edited by
        #3

        See my previous post regarding CArray. Simply create your employees in a CObArray and call the Serialize member function of the CObArray with a valid CArchive. This will alloy you to read and write your array with minimal amount of code.

        1 Reply Last reply
        0
        • B bhangie

          Hi there Can anyone advise. I have a class called Employee ok. Now i want the user to create employees by adding a name, empid and so on. Creating an Employee object // Employee *NewEmp = new Emp ?? I want the new employees details in a file .dat it keeps on creating one employee overriding the previous info. How can i create more than one employee Hit me over the knuckles if im way of! Am i using new wrong? or am i missing the hole new concept totaly thanks:-D

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          bhangie wrote: // Employee *NewEmp = new Emp ?? I assume you meant Employee *NewEmp = new Emp**loyee**? bhangie wrote: I want the new employees details in a file .dat it keeps on creating one employee overriding the previous info. So do you have something akin to:

          for each employee in list
          {
          open .dat file
          write employee info to file
          close .dat file
          }

          In other words, after writing all employees to the .dat file, what one employee is in the file: the first one in the list or the last? bhangie wrote: Am i using new wrong? or am i missing the hole new concept totaly You are using it correctly. However, at this point, there is no way to know if your design is sound.


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          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