I'm reading this book and I'm having trouble understanding some of the code that's written in it. The program is supposed to function as a basic database for a company. It should have employee objects that contain their salary, status in company (hired/fired) and have some methods that you can call on that object to update it.
This is the code they provide
#pragma once
#include <string>
namespace Records {
const int kDefaultStartingSalary = 30000;
class Employee
{
public:
Employee();
void promote(int raiseAmount = 1000);
void demote(int demeritAmount = 1000);
void hire(); // Hires or rehires the employee
void fire(); // Dismisses the employee
void display() const;// Outputs employee info to console
// Getters and setters
void setFirstName(const std::string& firstName);
const std::string& getFirstName() const;
void setLastName(const std::string& lastName);
const std::string& getLastName() const;
void setEmployeeNumber(int employeeNumber);
int getEmployeeNumber() const;
void setSalary(int newSalary);
int getSalary() const;
bool getIsHired() const;
private:
std::string mFirstName;
std::string mLastName;
int mEmployeeNumber;
int mSalary;
bool mHired;
};
}
I can't seem to understand why on the setFirstName and setLastName they are passing in by reference in the parameters, then in other setters/getters (like setSalary) they are passing by value. If someone could explain why this is good practice, that'd be excellent! They didn't explain their choice in the book.