TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: PHIL OHL
from: KURT KUZBA
date: 1998-04-07 07:03:00
subject: Pointer

PO>   I am having a minor problem getting pointers to work
PO>   correctly for me. I have made A pointer something like.
PO> void admin::raise(employee *luckyperson)
PO> {
PO> luckyperson->salary *= 1.75;
PO> }
PO> and I call the function in main.
PO> admin1 raise(employee1);
PO> this code however does not seem to work.  Help!
   Why is employee a struct and not a class?!
class Employee {
public:
   float Raise(float fR)    { return fSalary *= fR;   }
   float Cut(float fC)      { return fSalary /= fC;   }
   float Vacation(float fV) { return fVacation += fV; }
private:
   float fSalary, fVacation;
};
   This may not be the exact thing you seek, but your data
   objects should be better encapsulated. Just creating the
   employee object should give you the code to manipulate it.
   That aside, the following example should work:
#include 
typedef struct {
   float fSalary;
}  employee;
class Admin {
public:
   void Raise(employee *esE) { esE->fSalary *= 1.75; }
};
int main()
{
   Admin Boss;
   employee E1 = {{ 10.0f }};
   Boss.Raise(&E1);
   cout << "Employee rate is now " << E1.fSalary << "/hour.";
   cout << endl;
   return 0;
}
> ] Their only crime was being delicious........................
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.