3

このコードでは:

template <class TP> TP GCVVector<TP>::Remove( long Index )
{

    TP Result = m_ObjectList.at( Index );

    m_ObjectList.erase( &m_ObjectList.at( Index ) );

    return Result;
}

コンパイル時エラーが発生します:

/trnuser1/rmtrain/DevelopmentEnv/Telstra/USM/../../Generic/CoreObjects/GCVVector.h: In member function âTP GCVVector<TP>::Remove(long int) [with TP = GCVString]â:
/trnuser1/rmtrain/DevelopmentEnv/Generic/ModulePopulator/GCVMPState.cpp:69:   instantiated from here
/trnuser1/rmtrain/DevelopmentEnv/Telstra/USM/../../Generic/CoreObjects/GCVVector.h:241: error: no matching function for call to âstd::vector<GCVString, std::allocator<GCVString> >::erase(long int&)â
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:110: note: candidates are: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = GCVString, _Alloc = std::allocator<GCVString>]
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:122: note:                 typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = GCVString, _Alloc = std::allocator<GCVString>]
make[2]: *** [CMakeFiles/GCVMP.dir/trnuser1/rmtrain/DevelopmentEnv/Generic/ModulePopulator/GCVMPState.o] Error 1
make[1]: *** [CMakeFiles/GCVMP.dir/all] Error 2

誰かがデータを削除する方法を知っていますか?

4

2 に答える 2

8

std :: vector ::eraseの単一引数バージョンはイテレータを想定しており、要素のアドレスを渡しています。

正しい要素を削除するには、そのベクトルの有効なイテレータを渡す必要があります。std :: Advancem_ObjectList.begin()を使用して、増分を合計することにより、と増分を使用して1つを作成できます。

m_ObjectList.erase( std::advance(m_ObjectList.begin(), Index) );
于 2012-07-11T05:34:08.843 に答える
7
m_ObjectList.erase(m_ObjectList.begin() + Index );
于 2012-07-11T05:33:34.740 に答える