Hello folks, why in the function 'addTwo' in both cases variable salary equals to 400, independent of the variable passed to the constructor in the main function.
Code:
#include <iostream>
using namespace std;
class Employee{
private:
int idNum;
double salary;
public:
Employee(int, double);
double addTwo(Employee);
};
Employee::Employee(int id, double sal)
{
idNum = id;
salary = sal;
}
double Employee::addTwo(Employee emp)
{
double total;
cout << emp.salary << endl;
total = salary + emp.salary;
cout << salary << endl;
return total;
}
int main(void)
{
Employee clerk(1234, 400.);
Employee driver(3456, 650.);
double sum;
sum = clerk.addTwo(driver);
sum = clerk.addTwo(clerk);
return 0;
}