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)
|