がありstd::deque<CustomType>
、場所がわからないメンバーを削除しようとしています。したがって、私は最初にそれを見つけてから削除しています。
/*
Remove from - members, which is the private variable of std::deque<User> type
*/
void Group::remove_member(User u) {
if(this->is_member(u)) {
std::deque<User>::iterator iter;
iter = std::find(this->members.begin(), this->members.end(), u);
if(iter != this->members.end()) {
this->members.erase(iter);
}
}
}
ただし、コンパイラ (GCC) は、Operator Overloading が欠落しているように見えるエラーをスローしています。
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/algorithm:62,
from Group.cpp:4:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_algo.h: In function ‘_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = std::_Deque_iterator<User, User&, User*>, _Tp = User]’:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_algo.h:4224: instantiated from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = std::_Deque_iterator<User, User&, User*>, _Tp = User]’
Group.cpp:36: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_algo.h:174: error: no match for ‘operator==’ in ‘__first.std::_Deque_iterator<_Tp, _Ref, _Ptr>::operator* [with _Tp = User, _Ref = User&, _Ptr = User*]() == __val’
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_algo.h:178: error: no match for ‘operator==’ in ‘__first.std::_Deque_iterator<_Tp, _Ref, _Ptr>::operator* [with _Tp = User, _Ref = User&, _Ptr = User*]() == __val’
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_algo.h:182: error: no match for ‘operator==’ in ‘__first.std::_Deque_iterator<_Tp, _Ref, _Ptr>::operator* [with _Tp = User, _Ref = User&, _Ptr = User*]() == __val’
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_algo.h:186: error: no match for ‘operator==’ in ‘__first.std::_Deque_iterator<_Tp, _Ref, _Ptr>::operator* [with _Tp = User, _Ref = User&, _Ptr = User*]() == __val’
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_algo.h:194: error: no match for ‘operator==’ in ‘__first.std::_Deque_iterator<_Tp, _Ref, _Ptr>::operator* [with _Tp = User, _Ref = User&, _Ptr = User*]() == __val’
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_algo.h:198: error: no match for ‘operator==’ in ‘__first.std::_Deque_iterator<_Tp, _Ref, _Ptr>::operator* [with _Tp = User, _Ref = User&, _Ptr = User*]() == __val’
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_algo.h:202: error: no match for ‘operator==’ in ‘__first.std::_Deque_iterator<_Tp, _Ref, _Ptr>::operator* [with _Tp = User, _Ref = User&, _Ptr = User*]() == __val’