Is it possible use default arguments with member initialization lists?
Vector3::Vector3(double xI, double yI, double zI)
: x(xI=0), y(yI=0), z(zI=0)
{
}
The constructor always sets x, y, and z to 0 even if you call it with setting the arguments.
Vector3(double xI=0, double yI=0, double zI=0);
Vector3::Vector3(double xI, double yI, double zI)
: x(xI), y(yI), z(zI)
{
}
Also, if you are wondering what your code is doing, it's simply setting your parameters to be 0, then passing the value of them (now 0) to initialize the members.
The assignment operator =
always return what it has assigned to left side variable, in your case it return 0
, which get assigned to x
,y
and z
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With