Reputation: 203
How to change Axes (Axes const &crAxes) { *this = crAxes; }
into Axes (Axes const &crAxes) : (*this)(crAxes) {}
, so to copy the object inside the initialization list (before X, Y, and Z are initialized to their default value).
Changing form this:
struct Axes
{
Axes () : X(0.f), Y(0.f), Z(0.f) {}
Axes (Axes const &crAxes) { *this = crAxes; }
float X;
float Y;
float Z;
};
Into something like this:
struct Axes
{
Axes () : X(0.f), Y(0.f), Z(0.f) {}
Axes (Axes const &crAxes) : (*this)(crAxes) {}
float X;
float Y;
float Z;
};
Upvotes: 0
Views: 45
Reputation: 55897
You cannot do such thing in copy c-tor. Use simply
Axes(const Axes& rhs) : X(rhs.X), Y(rhs.Y), Z(rhs.Z) {}
However, there is no need in copy c-tor here, since default-implemented copy c-tor will do same things (memberwise-copy
).
Upvotes: 4