返回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.
更多推荐
发布评论