简体   繁体   English

编译器是否提供地址运算符?

[英]Does the compiler provide a address operator?

"How many functions does compiler implement for us if we don't define one?", I think that there are only 4 : “如果我们不定义一个函数,编译器将为我们实现多少个函数?”,我认为只有4

  • default ctor 默认ctor

  • copy ctor 复制ctor

  • assignment operator 赋值运算符

  • default destructor 默认析构函数

But someone says that there are still one or more default functions: address operator and address operator for const object ,is this right? 但是有人说仍然有一个或多个默认函数: address operatoraddress operator for const object ,对吗?

No, the address operator is not implicitly overloaded for a class type. 不,对于类类型,地址运算符不会隐式重载。 If you don't overload it, then the built-in operator can be applied to objects of that type, just as it can be applied to any object or function. 如果不重载,则可以将内置运算符应用于该类型的对象,就像可以将其应用于任何对象或函数一样。

Note that in modern C++, you can add "move constructor" and "move-assignment operator" to your list. 请注意,在现代C ++中,可以将“移动构造函数”和“移动分配运算符”添加到列表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM