Reading through The C++ Programming Language, 4th Edition, there's a class defined like so
class Vector
{
private:
int sz;
double *a;
public:
Vector(int s) :elem{new double[s]}, sz{s} {}
}
I'm a bit confused on how this constructor syntax works. I believe Vector(int s)
is creating a constructor function that takes one parameter s
, and that it initializes elem
and sz
. But why is there a :
? I thought functions bodies were surrounded by {}
? And so what do the empty braces {}
at the end serve?