class B{ public: B(){} ~B(){} B & operator=(const B & b){ std::cout << " cannot move -> copy " << std::endl; return *this; } B(const B & v){ std::cout << " cannot move -> copy " << std::endl; } // B(B && b) = delete; // uncomment this!};int main(){ B b( B{} ); }
编译器输出与clang 3.6(Live code)
main.cpp:27:7: error: call to deleted constructor of 'B' B b( B{} ); ^ ~~~main.cpp:21:5: note: 'B' has been explicitly marked deleted here B(B && b) = delete; ^1 error generated.解决方法 仍然声明具有已删除定义的函数.除此之外,它通常会参与重载决策 – 但如果重载决议实际上选择它,则程序格式不正确([dcl.fct.def.delete] / 2):
A program that refers to a deleted function implicitly or explicitly,other than to declare it,is ill-formed.
[ Note: This includes calling the function implicitly or explicitly and forming a pointer or pointer-to-member
to the function. It applIEs even for references in Expressions that are not potentially-evaluated. If a function
is overloaded,it is referenced only if the function is selected by overload resolution. —end note ]
这与从未声明过的函数不同.当然,不存在的声明不参与重载决策.
总结以上是内存溢出为你收集整理的c – 后备复制构造函数不工作?全部内容,希望文章能够帮你解决c – 后备复制构造函数不工作?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)