传递 const std::auto_ptr<> 作为 std::auto_ptr<_Tp>::运算符 std::auto_ptr_ref<_Tp1>() 的参数丢

passing const std::auto_ptr<> as this argument of std::auto_ptr<_Tp>::operator std::auto_ptr_ref<_Tp1>() discards qualifiers

本文关键字:lt ptr gt auto std 参数 Tp1 运算符 const 传递 作为      更新时间:2023-10-16

在编译代码时,我发现了这个错误,并且无法跟踪此错误,因为我在网上没有看到任何对此类错误的引用。请帮忙——

In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/memory:52,
                 from ./PbxComm.h:24,
                 from ./NsaComm.h:23,
                 from ./NsaBundle.h:22,
                 from NsaBundle.C:19:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h: In static member function âstatic _ForwardIterator std::__uninitialized_copy<<anonymous> >::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::auto_ptr<SnowTTan>*, std::vector<std::auto_ptr<SnowTTan>, std::allocator<std::auto_ptr<SnowTTan> > > >, _ForwardIterator = std::auto_ptr<SnowTTan>*, bool <anonymous> = false]â:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h:117:   instantiated from â_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::auto_ptr<SnowTTan>*, std::vector<std::auto_ptr<SnowTTan>, std::allocator<std::auto_ptr<SnowTTan> > > >, _ForwardIterator = std::auto_ptr<SnowTTan>*]â
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h:257:   instantiated from â_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::auto_ptr<SnowTTan>*, std::vector<std::auto_ptr<SnowTTan>, std::allocator<std::auto_ptr<SnowTTan> > > >, _ForwardIterator = std::auto_ptr<SnowTTan>*, _Tp = std::auto_ptr<SnowTTan>]â
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_vector.h:243:   instantiated from âstd::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::auto_ptr<SnowTTan>, _Alloc = std::allocator<std::auto_ptr<SnowTTan> >]â
./NsaForm207.h:45:   instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h:74: error: passing âconst std::auto_ptr<SnowTTan>â as âthisâ argument of âstd::auto_ptr<_Tp>::operator std::auto_ptr_ref<_Tp1>() [with _Tp1 = SnowTTan, _Tp = SnowTTan]â discards qualifiers
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h: In static member function âstatic _ForwardIterator std::__uninitialized_copy<<anonymous> >::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::auto_ptr<line_range>*, std::vector<std::auto_ptr<line_range>, std::allocator<std::auto_ptr<line_range> > > >, _ForwardIterator = std::auto_ptr<line_range>*, bool <anonymous> = false]â:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h:117:   instantiated from â_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::auto_ptr<line_range>*, std::vector<std::auto_ptr<line_range>, std::allocator<std::auto_ptr<line_range> > > >, _ForwardIterator = std::auto_ptr<line_range>*]â
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h:257:   instantiated from â_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::auto_ptr<line_range>*, std::vector<std::auto_ptr<line_range>, std::allocator<std::auto_ptr<line_range> > > >, _ForwardIterator = std::auto_ptr<line_range>*, _Tp = std::auto_ptr<line_range>]â
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_vector.h:243:   instantiated from âstd::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::auto_ptr<line_range>, _Alloc = std::allocator<std::auto_ptr<line_range> >]â
./NsaForm346.h:70:   instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h:74: error: passing âconst std::auto_ptr<line_range>â as âthisâ argument of âstd::auto_ptr<_Tp>::operator std::auto_ptr_ref<_Tp1>() [with _Tp1 = line_range, _Tp = line_range]â discards qualifiers
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h: In static member function âstatic _ForwardIterator std::__uninitialized_copy<<anonymous> >::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::auto_ptr<tsg_500>*, std::vector<std::auto_ptr<tsg_500>, std::allocator<std::auto_ptr<tsg_500> > > >, _ForwardIterator = std::auto_ptr<tsg_500>*, bool <anonymous> = false]â:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h:117:   instantiated from â_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::auto_ptr<tsg_500>*, std::vector<std::auto_ptr<tsg_500>, std::allocator<std::auto_ptr<tsg_500> > > >, _ForwardIterator = std::auto_ptr<tsg_500>*]â
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h:257:   instantiated from â_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::auto_ptr<tsg_500>*, std::vector<std::auto_ptr<tsg_500>, std::allocator<std::auto_ptr<tsg_500> > > >, _ForwardIterator = std::auto_ptr<tsg_500>*, _Tp = std::auto_ptr<tsg_500>]â
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_vector.h:243:   instantiated from âstd::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::auto_ptr<tsg_500>, _Alloc = std::allocator<std::auto_ptr<tsg_500> >]â
./NsaForm500.h:66:   instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_uninitialized.h:74: error: passing âconst std::auto_ptr<tsg_500>â as âthisâ argument of âstd::auto_ptr<_Tp>::operator std::auto_ptr_ref<_Tp1>() [with _Tp1 = tsg_500, _Tp = tsg_500]â discards qualifiers

从你的消息标题,看起来你正在丢弃'const'限定符从auto_ptr,这是不允许的

在vector(一般是STL容器)中使用auto_ptr是一个问题。我已经能够使用unique_ptr与适当的编译标志。这就解决了我的问题