c++ - 替代关键字表示

标签 c++

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/

相关文章:

命名空间中的 C++ 函数不起作用?

c++ - 为什么我可以从 char * const 值创建 char * vector ?

c++ - 无法自动调整 QScrollArea 的大小

c++ - 如何将 lua 脚本语言包含到 C++ XCode 中?

c++ - 如何处理 C++ 中的 "DNN module was not built with CUDA backend; switching to CPU"警告?

c++ - 如何动态创建函数数组?

c++ - ABC 中的多态静态常量成员变量?

c++ - 如何在c++中的开关中生成随机数

c++ - 跨进程 PostMessage、UIPI 限制和 UIAccess=”true”

c++ - 将 char vector 解析为 std::map<string, string>