Hello, I've bought the book, "Professional C++" as a way to teach myself more about the language and I keep seeing the & operator used. I assumed that they were being used to pass functions by reference but I see no pointers to make that true. What do they do in this context?
// this is a .h file, the code in question is on line 21,22,24,25. I'll also //include the CPP file if that helps.
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#pragma once
#include <string>
namespace Records{
const int kDefaultStartingSalary = 30000;
When you pass a const reference ie setFirstName(const std::string& firstName), you are not passing by value, so you don't create a copy of the parameter passed.
The & in these is not an operator. It is part of type definition. The function argument and return value are indeed references due to the &. However, a reference has nothing to do with pointers.