大佬教程收集整理的这篇文章主要介绍了c – 提供(空)用户定义的析构函数会导致编译错误,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <memory> class Test { std::unique_ptr<int> val; }; template <typename Type> class B { public: //destructor: // if I comment this out,the code compiles just fine: ~B() { } private: Test a; }; int main() { auto s = B<int>(); }
> Test的复制构造函数不存在,并且没有隐式创建,因为它会形成错误
>有些东西试图使用unique_ptr的已删除拷贝构造函数.
我知道unique_ptr不能被复制构造(除非参数是rvalue),因此编译器不可能为类Test生成有效的隐式复制构造函数.
我无法弄清楚为什么定义一个空的析构函数应该突然需要这些复制工具.显然,当使用unique_ptrs之类的东西时,这是不可能提供的.
这里的任何人都可以告诉我为什么会这样吗?
In file included from /usr/include/c++/4.7/list:64:0,from ../../DropBox/ProgrAMMing/C++/test/main.cpp:2: /usr/include/c++/4.7/bits/stl_list.h: In instantiation of 'std::_List_node<_Tp>::_List_node(_Args&& ...) [with _Args = {Const Test&}; _Tp = Test]': /usr/include/c++/4.7/ext/new_allocator.h:110:4: required from 'void __gnu_cxx::new_allocator<_Tp>::construct(_UP*,_Args&& ...) [with _Up = std::_List_node<Test>; _Args = {Const Test&}; _Tp = std::_List_node<Test>]' /usr/include/c++/4.7/bits/stl_list.h:503:8: required from 'std::list<_Tp,_Alloc>::_Node* std::list<_Tp,_Alloc>::_M_create_node(_Args&& ...) [with _Args = {Const Test&}; _Tp = Test; _Alloc = std::allocator<Test>; std::list<_Tp,_Alloc>::_Node = std::_List_node<Test>]' /usr/include/c++/4.7/bits/stl_list.h:1533:63: required from 'void std::list<_Tp,_Alloc>::_M_insert(std::list<_Tp,_Alloc>::iterator,_Args&& ...) [with _Args = {Const Test&}; _Tp = Test; _Alloc = std::allocator<Test>; std::list<_Tp,_Alloc>::iterator = std::_List_iterator<Test>]' /usr/include/c++/4.7/bits/stl_list.h:997:9: required from 'void std::list<_Tp,_Alloc>::push_BACk(const value_type&) [with _Tp = Test; _Alloc = std::allocator<Test>; std::list<_Tp,_Alloc>::value_type = Test]' /usr/include/c++/4.7/bits/stl_list.h:1466:6: required from 'void std::list<_Tp,_Alloc>::_M_initialize_dispatch(_InputIterator,_InputIterator,std::__false_typE) [with _InputIterator = std::_List_const_iterator<Test>; _Tp = Test; _Alloc = std::allocator<Test>]' /usr/include/c++/4.7/bits/stl_list.h:582:9: required from 'std::list<_Tp,_Alloc>::list(const std::list<_Tp,_Alloc>&) [with _Tp = Test; _Alloc = std::allocator<Test>; std::list<_Tp,_Alloc> = std::list<Test>]' ../../DropBox/ProgrAMMing/C++/test/main.cpp:11:7: required from here /usr/include/c++/4.7/bits/stl_list.h:115:71: error: use of @R_489_9421@ed function 'Test::Test(const Test&)' ../../DropBox/ProgrAMMing/C++/test/main.cpp:5:7: note: 'Test::Test(const Test&)' is implicitly @R_489_9421@ed because the default deFinition would be ill-formed: ../../DropBox/ProgrAMMing/C++/test/main.cpp:5:7: error: use of @R_489_9421@ed function 'std::unique_ptr<_Tp,_Dp>::unique_ptr(const std::unique_ptr<_Tp,_Dp>&) [with _Tp = int; _Dp = std::default_@R_489_9421@e<int>; std::unique_ptr<_Tp,_Dp> = std::unique_ptr<int>]' In file included from /usr/include/c++/4.7/memory:86:0,from ../../DropBox/ProgrAMMing/C++/test/main.cpp:3: /usr/include/c++/4.7/bits/unique_ptr.h:262:7: error: declared here
以上是大佬教程为你收集整理的c – 提供(空)用户定义的析构函数会导致编译错误全部内容,希望文章能够帮你解决c – 提供(空)用户定义的析构函数会导致编译错误所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。