bool eq(int x, int y) {
return x == y;
}
TEST_CASE("operator vs. function call") {
int x = 1;
int y = 2;
CHECK(x == y);
CHECK(eq(x, y));
}
我得到以下輸出
/path/to/MyTest.cpp:8: Failure:
CHECK(x == y)
with expansion:
1 == 2
/path/to/MyTest.cpp:9: Failure:
CHECK(eq(x, y))
with expansion:
false
爲什麼能趕上轉換x
和y
到字符串運算符表達式x == y
但不在函數調用表達式eq(x, y)
中?是它在某種程度上可能字符串化以類似的方式函數調用表達式得到的輸出是這樣的:
/path/to/MyTest.cpp:9: Failure:
CHECK(eq(x, y))
with expansion:
eq(1, 2)