传递const std :: auto_ptr<>因为std :: auto_ptr< _Tp> :: operator std :: auto_ptr_ref< _Tp1>()的这个参数丢弃了限定符

时间:2013-04-22 09:04:49

标签: c++ auto pointers

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

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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