返回c ++ 11中已删除函数的类型(return type of deleted functions in c++11)

编程入门 行业动态 更新时间:2024-10-25 21:25:19
返回c ++ 11中已删除函数的类型(return type of deleted functions in c++11)

在c ++ 11中,我们可以使用delete禁用复制构造函数和赋值运算符:

class A { A(const A&) = delete; A& operator=(const A&) = delete; }

有一天,我的同事使用void返回类型而不是引用。

class A { A(const A&) = delete; void operator=(const A&) = delete; }

这个还好吗?

例如,如果我有

A a, b, c; a = b = c;

这会有用吗?

In c++ 11, we could disable copy constructor and assignment operator, with delete:

class A { A(const A&) = delete; A& operator=(const A&) = delete; }

One day, my colleague use the void return type rather than the reference.

class A { A(const A&) = delete; void operator=(const A&) = delete; }

Is this one also ok?

e.g., if i have

A a, b, c; a = b = c;

will this work?

最满意答案

返回类型不是c ++中函数签名的一部分(这也是为什么不能仅通过返回类型重载函数的原因)。 所以没关系,因为在名称查找过程中仍会找到已删除的功能。 您可能有编译器警告,具体取决于您的编译器版本/设置。

Return types are not a part of the function signature in c++ (this is also why you can't overload functions only by the return type). So it's ok because your deleted function will still be found during the name lookup. You might have compiler warnings though, depending on your compiler version/settings.

更多推荐

本文发布于:2023-07-20 12:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1199639.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   类型   return   functions   deleted

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!