Due to some legacy C code, I have the following POD struct defining 2D coordinates; and a C++ class inheriting from it in order to provide various operations:
struct coord
{
double x;
double y;
};
class CoordClass : public coord
{
// Contains functions like...
const CoordClass& operator+=(const CoordClass& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}
double Magnitude() const { return std::sqrt(x*x + y*y); }
};
At present, CoordClass defines a constructor:
CoordClass(double xx, double yy) { x = xx; y = yy; }
Given x and y are members of the POD base struct coord, is it possible to write that constructor as an initialiser list and empty body instead? Answers considering both C++03 and C++11 interest me.