I am now in Advanced C++ and my teacher is just part of the office staff, therefor does not teach nor know anything about c++. So I am really struggling.
This is just a basic constructor, however it's got some extra line after it preceded by a colon.
The below code is an overloaded function?
What does " : CommissionEmployee( first, last, ssn, sales, rate )" do?
Theres also a line in the header like this, what does it do?
The colon indicates the start of the member initialization list. The member initialization list contains constructor calls for any base classes as well as member variables. In this case CommisionEmployee(stuff) indicates that the argument list after the type name is being used as the arguments for the base class constructor.
The code you post is quite complex so possibly harder to understand this in isolation. Simpler example:
class A
{
private:
int x;
public:
A(int v) : x(v) { } // sets the member 'x' to the argument
};
class B : public A
{
public:
B(int v) : A(v) { } // passes the argument to A's constructor
};
Before a derived class is constructed, its parent class(es) are constructed. If they require parameters, you have to use the initializer syntax. Using it for members of the actual class is good where possible as it avoids default initializing then assignment. For example:
// comments do not consider compiler optimisations
class A
{
private:
std::string s;
public:
A(const std::string &v){ s=v; } // s is initialized to "", then assigned the value of v
A(const std::string &v) : s(v) { } // s is initialized with v
};
For classes with expensive initializing or assignment, this is more efficient so it is generally good practice to initialize here when you can. It also makes it harder to accidentally use non-initialized values in the body of the constructor.
Something else I like is the way you can avoid nameclash between members and parameters.
class BasePlusCommissionEmployee : public CommissionEmployee
{
The above line in the header essentially means that the class BasePlusCommissionEmployee inherits from the class CommissionEmployee. This is an "is a" relationaship, or BasePlusCommissionEmployee is a CommissionEmployee
The above code in the constructor basically tells the compiler to pass the constructor arguements first, last, ssn, sales, and rate into the constructor of the base class. This lets the base class logic take care of creating it's own members, and the derived class then only has to deal with the salary parameter. This is just a nice handy way of creating a derived class without having to copy and paste the code from the base class constructor.