我們先看2段外文:
In some contexts, unevaluated operands appear (5.2.8, 5.3.3, 5.3.7, 7.1.6.2). An unevaluated operand is not evaluated. An unevaluated operand is considered a full-exPRession. [ Note: In an unevaluated operand, a non-static class member may be named (5.1) and naming of objects or functions does not, by itself, require that a definition be provided (3.2). —end note ] + 5.2.8 covers typeid + 5.3.3 covers sizeof + 5.3.7 covers noexcep + 7.1.6.2 covers simple type specifiers such as auto and decltype and POD types like int, char, double etc.
The operands of the four operators typeid, sizeof, noexcept, and decltype (since C++11) are expressions that are not evaluated (unless they are polymorphic glvalues and are the operands of typeid), since these operators only query the compile-time properties of their operands. Thus, std::size_t n = sizeof(std::cout << 42); does not perform console output. The unevaluated operands are considered to be full expressions even though they are syntactically operands in a larger expression (for example, this means that sizeof(T()) requires an accessible T::~T)
可以這樣理解: 1. unevaluated operand是不被評估的,它是一個完整的表達式。c++中4個操作符typeid,sizeof, noexcept,decltype對應的表達式是不需要被評估的。 2. unevaluated operand僅僅是查詢編譯期間的相關屬性,并不會生產運行期的代碼。 3. unevaluated operand不會去完全編譯表達式,即不會完全檢查編譯的錯誤,但是參數值和需要推導返回值的地方會執行編譯檢查。
新聞熱點
疑難解答
圖片精選