I want to initialize a property of a class that holds a reference to another class by passing such a reference as a parameter to the constructor. However I receive an error:
You are attempting to assign to bank, not initialize it:
TaxSquare::TaxSquare(int anID, int amount, Bank& theBank) : Square(anID)
{
// These are assignments
taxAmount = amount;
bank = theBank;
}
bank is a reference, and therefore it must be initialized. You do so by putting it in the initializer list:
TaxSquare::TaxSquare(int anID, int amount, Bank& theBank)
: Square(anID), taxAmount(amount), bank(theBank)
{}