Can I get some help with explanation of the following code?
#include
class Vector {
private:
double∗ elem; // pointer to the el
Vector(int s)
defines a constructor - a special method that is called when object is created.
:elem{new double[s]}, sz{s}
is a initializer list - it initializes object's fields. The whole part:
Vector(int s):elem{new double[s]}, sz{s} {}
Works same as
Vector(int s) {
elem = new double[s];
sz = s;
}
However, initializer lists can be used to initialize constants and references.