gpt4 book ai didi

c++ - 为什么 C++ 需要运算符同义词?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:06:56 25 4
gpt4 key购买 nike

<分区>

在维基百科上查找 C++ 的运算符列表时,我发现了一篇关于 operator synonyms 的文章:

C++ defines[6] keywords to act as aliases for a number of operators: and (&&), bitand (&), and_eq (&=), or (||), bitor (|), or_eq (|=), xor (^), xor_eq (^=), not (!), not_eq (!=), and compl (~). These can be used exactly the same way as the punctuation symbols they replace, as they are not the same operator under a different name, but rather simple token replacements for the name (character string) of the respective operator. This means that the expressions (a > 0 and flag) and (a > 0 && flag) have identical meanings. It also mean that, for example, the bitand keyword may be used to replace not only the bitwise-and operator but also the address-of operator, and it can even be used to specify reference types (e.g., int bitand ref = n). The ISO C specification makes allowance for these keywords as preprocessor macros in the header file iso646.h. For compatibility with C, C++ provides the header ciso646, inclusion of which has no effect.

然后我想知道:为什么我们需要这些运算符同义词?如果有人提供一些用例,那就太好了。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com