C++ 标准 (ISO/IEC 14882:03) 声明如下 (2.11/2):
Furthermore, the alternative representations shown in Table 4 for certain operators and punctuators (2.5) are reserved and shall not be used otherwise:
and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq
我已经尝试将它们与多个编译器一起使用,没有出现问题。
据我了解,我只被禁止将它们用作标识符名称。 英语不是我的第一语言,所以如果有人可以验证我确实可以在表达式中使用这些按位助记符(即“int i = not 0;”),那就太好了。
编辑:我可能应该指出,我不会使用这些(如果它们有效的话)来隐藏代码。这只是为了一般知识。 =)
谢谢!
最佳答案
是的,您可以使用它们来替代名称标记。例如:
struct foo {
// defines a destructor
compl foo() { }
};
您的示例也可以。然而,它会将一个 one 存储到 i 中。如果你想使用 bitwise not,你使用 compl (~):
int i = compl 0;
关于c++ - 替代关键字表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/500362/