2 Replies - 745 Views - Last Post: 09 February 2010 - 01:32 PM Rate Topic: -----

#1 react05   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 29-September 09

help with pointer notation

Posted 09 February 2010 - 01:16 PM

Hey. How would I change this code
 else
     {
       Worker *Employee = new Worker[records];
       int hour;
       string name;
       float rate;
       for (int i = 0; i < records; i++)
       {
         infile>>name;
         infile>>rate;
         infile>>hour;
         Employee[i].setValue(name, rate, hour);
         Employee[i].displayWorker();
       }
     } 

from array notation to pointer notation.
I tried changing it to
*(Employee + i)setValue(name, rate, hour); *(Employee + i).displayWorker();


Is This A Good Question/Topic? 0
  • +

Replies To: help with pointer notation

#2 Martyn.Rae   User is offline

  • The programming dinosaur
  • member icon

Reputation: 557
  • View blog
  • Posts: 1,438
  • Joined: 22-August 09

Re: help with pointer notation

Posted 09 February 2010 - 01:22 PM

*(Employee + i)setValue(name, rate, hour); *(Employee + i).displayWorker();



You have missed a period. It should be

*(Employee + i).setValue(name, rate, hour); *(Employee + i).displayWorker();



Also, and this is just a coding thing, try not to put more than one statement on a line. It becomes a nightmare when you are trying to debug a program.

    *(Employee + i).setValue(name, rate, hour);
    *(Employee + i).displayWorker();



is so mush easier.

Hope that helps.

[/code]
Was This Post Helpful? 0
  • +
  • -

#3 react05   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 29-September 09

Re: help with pointer notation

Posted 09 February 2010 - 01:32 PM

Oh I see now. Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1