So this code
Vector(int s):elem{new double[s]}, sz{ s }{}
is more or less the same as
Vector(int s)
{
elem = new double[s];
sz = s;
}
The first difference is that the books code uses an initialiser list instead of assignment to give values to the class variables. The advantage of an initialiser list is that it initialises the variables directly by calling the appropriate constructor. The alternative form first default constructs the variables and then assigns to them, a two step process which is potentially less efficient. But in your case the variables are a pointer and an integer, for these types there's little difference between using an initialiser list and using assignment, but an initialiser list should still be prefered to be consistent with the times when it does make a difference. Any C++ book should explain initialiser lists.
The second difference is that the books code is using uniform initialisation syntax. You can tell this because it uses {}
instead of the usual ()
. But in the case of an initialiser list I think this makes no difference.