I am reading Programming Principles and Practice Using C++ written by Bjarne Stroustrup, and I am stuck at page 204, about constexpr, seems like I cannot make the code example in the book compile:
constexpr double xscale = 10;
constexpr double yscale = 0.8;
constexpr Point scalePoint(Point p)
{
return{ xscale * p.x, yscale * p.y };
}
Point is a class with two members, x y, and a constructor:
class Point
{
double x;
double y;
Point(double inX, double inY)
: x(inX),y(inY)
{
}
};
The error I am getting is:
Error (active)
function "scalePoint" (declared at line 13) was previously not declared constexpr
Point, you might want to make the constructorconstexpras well.scalePointsomewhere outside the code you posted which is declared withoutconstexpr.