我无法为基本的矢量图形点类编译此测试用例。请帮助我找出丢失的内容。谢谢!
编译错误:必须使用常量表达式初始化Constexpr变量“ i”
测试用例:
TEST(constexprPoint, Point)
{
constexpr int i = VG::Point{4, 5}.getX(); // <-- compile error
CHECK_EQUAL(i, 4);
}
头文件:
namespace VG {
class Point{
public:
Point(const int x, const int y) : myX{x},myY{y} {}
constexpr int getX() const;
constexpr int getY() const;
private:
const int myX, myY;
};
}
源文件:
namespace VG {
constexpr int Point::getX() const {
return myX;
}
constexpr int Point::getY() const {
return myY;
}
}