C ++中运算符和函数之间的区别? [英] Difference between operator and function in C++?
问题描述
我可以使用一些帮助理解C ++中的以下内容,特别是运算符和函数之间的区别:
- 什么是运算符
- 什么是功能?
- 它们之间有什么区别?
- c c $
操作符在编译时对操作数进行操作?它们总是在编译时运行吗? (如C ++中的
sizeof()
)
是 +
, -
, + =
等等(见13.5)。他们没有意义。在语义分析期间,确定运算符的含义。
函数是一个构造函数,析构函数,转换函数(看起来像 operator type()
)或操作符函数(功能模板专门化和实例化可以依次产生这些)。
是操作符例如 operator +
。这些是在所有方面的函数,并且与通常函数的唯一区别是它们可能被隐式调用,并且它们有一个有趣的名字。
一些操作符有一个内置的含义,可以由程序员修改。一个是简单地通过说出内置的操作符来说明操作符的内在含义(见5/3)。但是,如果将这样的运算符应用于定义了内置含义的操作数,则仅允许在少数情况下更改该含义(这些是赋值,地址和逗号运算符,见13.5 / 6)。
I could use some help understanding the following in C++, particularly the difference between an operator and a function:
- What is an operator?
- What is a function?
- What is the difference between them?
- Is a user-defined
operator+()
a function or an operator? - Can an operator operate on operands at compile-time? Do they always operate at compile time? (like
sizeof()
in C++)
An operator is a symbol like +
, -
, +=
and so forth (see 13.5). They don't carry a meaning. During semantic analysis, the meaning of an operator is determined.
A function is a constructor, destructor, conversion function (that looks like operator type()
) or operator function (function template specialization and instantiation can yield these in turn).
An operator function is something that implements an operator (see 13.5). An example is operator+
. These are functions in all respects, and the only difference to "usual" functions is that they may be called implicitly and they have a funny name.
Some operators have a built-in meaning, that can be changed by the programmer. One refers to the built-in meaning of an operator simply by saying built-in operator (see 5/3). However, if such an operator is applied on operands for which a built-in meaning is defined, changing that meaning is only allowed for a few cases (these are assignment, address-of and the comma operator, see 13.5/6).
这篇关于C ++中运算符和函数之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!