Iterating through 2D vector to delete objects from memory - c++

I have a 2D vector which contains objects.
std::vector<std::vector<List> > ListPos;
ListPos.clear();
std::vector<List> initPV;
ListPos.push_back(initPV);
List newList;
//... some code to determine where the object needs to go and vector resized to accommodate ...//
ListPos[ThisY].insert(ListPos[ThisY].begin()+ThisX, newList);
Objects are created and the vector resized as needed, my question is how can I loop through the vector and delete any objects I'm not using(given some location data such asif(![3][7]) to free up memory.
Also can I do anything with the vector to free up memory for the space that the object was using after it being deleted?
| List | List | List |
-------------------------------
| List | List | Delted | List |
-------------------------------
| Deleted | List |
So in the above representation I have a 3 row vector with up to 4 cols, so where it says deleted that would be where the position of the objects have been deleted from.
I'm guessing that once the objects had been deleted from memory that the space in the vector would just.. 'zero'?
I should note that where objects get deleted from say [2][0] I need to leave available for another object to go in its place, but cant allow [2][1] to take its place, if that makes sense. [2][1] needs to stay at [2][1]
I have tried the following (actual code)
for (std::vector<std::vector<List*> >::iterator i = Area::AreaControl.ListPos.begin(); i != Area::AreaControl.ListPos.end();++i)
{
for (std::vector<List*>::iterator j = i->begin(); j != i->end();++i)
{
if(j != Area::AreaControl.ListPos[0][0]) {
// Delete
}
}
}
But no dice :(
error: conversion from ‘std::vector<List>::iterator {aka __gnu_cxx::__normal_iterator<List*, std::vector<List> >}’ to non-scalar type ‘std::vector<List*>::iterator {aka __gnu_cxx::__normal_iterator<List**, std::vector<List*> >}’ requested
src/Void_OnLoop.cpp:62:73: error: no match for ‘operator!=’ in ‘j != i.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = std::vector<List>*, _Container = std::vector<std::vector<List> >, __gnu_cxx::__normal_iterator<_Iterator, _Container>::pointer = std::vector<List>*]()->std::vector<_Tp, _Alloc>::end [with _Tp = List, _Alloc = std::allocator<List>, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<List*, std::vector<List> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = List*]()’
src/Void_OnLoop.cpp:62:73: note: candidates are:
/usr/include/c++/4.6/ext/new_allocator.h:128:5: note: template<class _Tp> bool __gnu_cxx::operator!=(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
/usr/include/c++/4.6/bits/stl_iterator.h:817:5: note: template<class _Iterator, class _Container> bool __gnu_cxx::operator!=(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
/usr/include/c++/4.6/bits/stl_iterator.h:811:5: note: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator!=(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
/usr/include/c++/4.6/bits/streambuf_iterator.h:200:5: note: template<class _CharT, class _Traits> bool std::operator!=(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
/usr/include/c++/4.6/bits/basic_string.h:2497:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/include/c++/4.6/bits/basic_string.h:2485:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/basic_string.h:2473:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/postypes.h:223:5: note: template<class _StateT> bool std::operator!=(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
/usr/include/c++/4.6/bits/stl_vector.h:1297:5: note: template<class _Tp, class _Alloc> bool std::operator!=(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
/usr/include/c++/4.6/bits/allocator.h:137:5: note: template<class _Tp> bool std::operator!=(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)
As you can probably tell from my code, I'm no master.. Any suggestions will be highly appreciated!

In your first code block you define a std::vector<std::vector<List> >, i.e., a vector of vectors of List and in the second block you loop over std::vector<std::vector<List*> >, i.e., a vector of vector of pointer to List. Hence, the applied iterators are different types which cannot be converted into each other.
I'd recommend to use typedefs for the inner and outer vector to ensure your types are consistent.
And remember that erasing an element by an iterator invalidates the iterator, but returns a new iterator pointing to the next element.

Related

Need help understanding why this invalid C++ code compiles successfully

The following code compile correctly for me in some environments (e.g. on compiler explorer with GCC 9.3.0) and complains in others (CentOS 7.9.2009 (Core), GCC 9.3.1).
#include <iostream>
#include <string>
using namespace std;
int main() {
std::string name="aakash";
name.erase(name.begin()+2, name.cend());
return 0;
}
When I get an error, the error is:
test.cpp:6:40: error: no matching function for call to 'std::basic_string<char>::erase(__gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, std::basic_string<char>::const_iterator)'
6 | name.erase(name.begin()+2, name.cend());
| ^
In file included from /opt/rh/devtoolset-9/root/usr/include/c++/9/string:55,
from /opt/rh/devtoolset-9/root/usr/include/c++/9/bits/locale_classes.h:40,
from /opt/rh/devtoolset-9/root/usr/include/c++/9/bits/ios_base.h:41,
from /opt/rh/devtoolset-9/root/usr/include/c++/9/ios:42,
from /opt/rh/devtoolset-9/root/usr/include/c++/9/ostream:38,
from /opt/rh/devtoolset-9/root/usr/include/c++/9/iostream:39,
from test.cpp:1:
/opt/rh/devtoolset-9/root/usr/include/c++/9/bits/basic_string.h:4698:7: note: candidate: 'std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::erase(std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]'
4698 | erase(size_type __pos = 0, size_type __n = npos)
| ^~~~~
/opt/rh/devtoolset-9/root/usr/include/c++/9/bits/basic_string.h:4698:23: note: no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<char*, std::basic_string<char> >' to 'std::basic_string<char>::size_type' {aka 'long unsigned int'}
4698 | erase(size_type __pos = 0, size_type __n = npos)
| ~~~~~~~~~~^~~~~~~~~
/opt/rh/devtoolset-9/root/usr/include/c++/9/bits/basic_string.h:4714:7: note: candidate: 'std::basic_string<_CharT, _Traits, _Alloc>::iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(std::basic_string<_CharT, _Traits, _Alloc>::iterator) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; typename _Alloc::rebind<_CharT>::other::pointer = char*]'
4714 | erase(iterator __position)
| ^~~~~
/opt/rh/devtoolset-9/root/usr/include/c++/9/bits/basic_string.h:4714:7: note: candidate expects 1 argument, 2 provided
/opt/rh/devtoolset-9/root/usr/include/c++/9/bits/basic_string.h:4734:7: note: candidate: 'std::basic_string<_CharT, _Traits, _Alloc>::iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(std::basic_string<_CharT, _Traits, _Alloc>::iterator, std::basic_string<_CharT, _Traits, _Alloc>::iterator) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; typename _Alloc::rebind<_CharT>::other::pointer = char*]'
4734 | erase(iterator __first, iterator __last);
| ^~~~~
/opt/rh/devtoolset-9/root/usr/include/c++/9/bits/basic_string.h:4734:40: note: no known conversion for argument 2 from '__normal_iterator<const char*,[...]>' to '__normal_iterator<char*,[...]>'
4734 | erase(iterator __first, iterator __last);
| ~~~~~~~~~^~~~~~
| ~~~~~~~~~^~~~~~
The error looks reasonable to me because, as per C++ documentation, both arguments to std::basic_string::erase should either be of type iterator or const_iterator.
So, when it works (e.g. here), what allows it to work?
Since C++11, both arguments to the two-iterator overload of std::string::erase() are const_iterator. See form #3 on this cppreference page (the one you linked in your question).
Further, the C++11 Standard requires that a conatiner's iterator types are convertible to the equivalent const_iterator.
From this Draft C++11 Standard, in §23.2.1 [container.requirements.general], Table 96 has the following entry (bold emphasis mine):
Expression
Return Type
Operational Semantics
Assertion/note
…
X::iterator
iterator type whose value type is T
any iterator category that meets the forward iterator requirements. convertible to X::const_iterator.
…
So, in your call to .erase(), the first argument is being converted to a string::const_iterator.
Thus, the bug is in those compilers that don't accept your call, assuming you have set them also to use the C++11 (or later) standard.

Using my custom iterator with STL algorithms

I'm trying to create my own iterator, and I've got it working as expected with the std::generate algorithm. However, when I try std::max_element of std::find, I get some cryptic errors.
Here is the interface for my iterator:
template <typename GridT,
typename GridPtr,
typename GridRef,
template <typename> class ShapeT>
class GridIterator
{
public:
typedef GridIterator<GridT, GridPtr, GridRef, ShapeT> Iterator;
// Iterator traits - typedefs and types required to be STL compliant
typedef std::ptrdiff_t difference_type;
typedef typename GridT::Element value_type;
typedef typename GridT::Element* pointer;
typedef typename GridT::Element& reference;
typedef size_t size_type;
std::forward_iterator_tag iterator_category;
GridIterator(GridT& grid,
ShapeT<typename GridT::Resolution> shape,
Index iterStartIndex);
~GridIterator();
Iterator& operator++();
Iterator operator++(int);
typename GridT::Element& operator*();
typename GridT::Element* operator->();
bool operator!=(const GridIterator& rhs) const;
bool operator==(const GridIterator& rhs) const;
....
}
Using std::find, I get this error:
In file included from /usr/include/c++/4.6/algorithm:63:0,
from ./grid/Map_Grid.h:11,
from main.cpp:4: /usr/include/c++/4.6/bits/stl_algo.h: In function ‘_IIter
std::find(_IIter, _IIter, const _Tp&) [with _IIter =
Map::GridIterator<Map::Grid<double, int>, Map::Grid<double, int>,
Map::Grid<double, int>&, Map::Rectangle>, _Tp = int]’:
main.cpp:103:50: instantiated from here
/usr/include/c++/4.6/bits/stl_algo.h:4404:45: error: no matching
function for call to
‘__iterator_category(Map::GridIterator<Map::Grid<double, int>,
Map::Grid<double, int>, Map::Grid<double, int>&, Map::Rectangle>&)’
/usr/include/c++/4.6/bits/stl_algo.h:4404:45: note: candidate is:
/usr/include/c++/4.6/bits/stl_iterator_base_types.h:202:5: note:
template typename std::iterator_traits::iterator_category
std::__iterator_category(const _Iter&)
With std::max_element :
In file included from /usr/include/c++/4.6/bits/char_traits.h:41:0,
from /usr/include/c++/4.6/ios:41,
from /usr/include/c++/4.6/ostream:40,
from /usr/include/c++/4.6/iostream:40,
from ./grid/Map_GridIterator.h:7,
from ./grid/Map_Grid.h:8,
from main.cpp:4: /usr/include/c++/4.6/bits/stl_algobase.h: In function ‘const _Tp&
std::max(const _Tp&, const _Tp&) [with _Tp =
Map::GridIterator<Map::Grid<double, int>, Map::Grid<double, int>,
Map::Grid<double, int>&, Map::Rectangle>]’: main.cpp:102:60:
instantiated from here /usr/include/c++/4.6/bits/stl_algobase.h:215:7:
error: no match for ‘operator<’ in ‘__a < __b’
/usr/include/c++/4.6/bits/stl_algobase.h:215:7: note: candidates are:
/usr/include/c++/4.6/bits/stl_pair.h:207:5: note: template<class _T1,
class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&,
const std::pair<_T1, _T2>&)
/usr/include/c++/4.6/bits/stl_iterator.h:291:5: note: template bool std::operator<(const std::reverse_iterator<_Iterator>&, const
std::reverse_iterator<_Iterator>&)
/usr/include/c++/4.6/bits/stl_iterator.h:341:5: note: template<class
_IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_IteratorL>&, const
std::reverse_iterator<_IteratorR>&)
/usr/include/c++/4.6/bits/stl_iterator.h:1049:5: note: template<class
_IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_IteratorL>&, const
std::move_iterator<_IteratorR>&)
/usr/include/c++/4.6/bits/stl_iterator.h:1055:5: note: template bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
/usr/include/c++/4.6/bits/basic_string.h:2510:5: note: template<class
_CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const
std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/basic_string.h:2522:5: note: template<class
_CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT)
/usr/include/c++/4.6/bits/basic_string.h:2534:5: note: template<class
_CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&) /usr/include/c++/4.6/bits/stl_vector.h:1290:5: note: template<class
_Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&) /usr/include/c++/4.6/tuple:586:5: note: template<class ... _TElements,
class ... _UElements> bool std::operator<(const std::tuple<_TElements
...>&, const std::tuple<_Elements ...>&)
You are missing a typedef keyword for declaring an alias indicating the iterator category:
// Iterator traits - typedefs and types required to be STL compliant
//...
typedef std::forward_iterator_tag iterator_category;
~~~~~~^
Without the typedef, you are actually declaring a data member.
To avoid such mistakes, you can utilize the std::iterator class template as a base class, instead of defining those aliases on your own:
class GridIterator : public std::iterator<std::forward_iterator_tag
, typename GridT::Element>

C++: overriding function from templated base class

Here's the simple version. Below, I fully explain the real-world use case.
I've got two classes:
template<class T>
class Base {
protected:
virtual void foo();
std::map<std::string*, T*> things;
};
class Derived : public Base<int> {
protected:
void foo();
};
template<class T>
void Base<T>::foo() {
for (auto itr = things.begin(); itr < things.end(); ++itr) {
}
}
void Derived::foo() {
for (auto itr = things.begin(); itr < things.end(); ++itr) {
}
}
I run into problems with the for loop condition in the Derived implementation of foo:
example.cpp: In member function ‘virtual void Derived::foo()’:
example.cpp:23:53: error: no match for ‘operator<’ in ‘itr < ((Derived*)this)->Derived::<anonymous>.Base<int>::things.std::map<_Key, _Tp, _Compare, _Alloc>::end<std::basic_string<char>*, int*, std::less<std::basic_string<char>*>, std::allocator<std::pair<std::basic_string<char>* const, int*> > >()’
example.cpp:23:53: note: candidates are:
In file included from /usr/include/c++/4.7/string:54:0,
from example.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:2590:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.7/bits/basic_string.h:2590:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: mismatched types ‘const _CharT*’ and ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’
In file included from /usr/include/c++/4.7/string:54:0,
from example.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:2578:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/include/c++/4.7/bits/basic_string.h:2578:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
In file included from /usr/include/c++/4.7/string:54:0,
from example.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:2566:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.7/bits/basic_string.h:2566:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
In file included from /usr/include/c++/4.7/map:62:0,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_multimap.h:822:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
/usr/include/c++/4.7/bits/stl_multimap.h:822:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::multimap<_Key, _Tp, _Compare, _Alloc>’
In file included from /usr/include/c++/4.7/map:61:0,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_map.h:906:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
/usr/include/c++/4.7/bits/stl_map.h:906:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::map<_Key, _Tp, _Compare, _Alloc>’
In file included from /usr/include/c++/4.7/map:60:0,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_tree.h:873:5: note: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
/usr/include/c++/4.7/bits/stl_tree.h:873:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:1063:5: note: template<class _Iterator> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
/usr/include/c++/4.7/bits/stl_iterator.h:1063:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::move_iterator<_Iterator>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:1057:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
/usr/include/c++/4.7/bits/stl_iterator.h:1057:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::move_iterator<_Iterator>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:349:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
/usr/include/c++/4.7/bits/stl_iterator.h:349:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::reverse_iterator<_Iterator>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:299:5: note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/include/c++/4.7/bits/stl_iterator.h:299:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::reverse_iterator<_Iterator>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:65:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_pair.h:212:5: note: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/include/c++/4.7/bits/stl_pair.h:212:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::pair<_T1, _T2>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:838:5: note: template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
/usr/include/c++/4.7/bits/stl_iterator.h:838:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:832:5: note: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
/usr/include/c++/4.7/bits/stl_iterator.h:832:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
Why doesn't this work, and what should I be doing to fix it?
P.S.: I know that this is a prime opportunity to use template specialization, but I don't think that is appropriate for my use case.
Here's the full story.
I'm making a scene graph with several types of nodes. Some of the important ones for this issue are:
SceneParent
SceneRegion
SceneGroup
SceneComponent
They each play the following roles:
SceneParent contains a set of children, of template type T.
SceneRegion extends SceneParent, specifying T as SceneParent
SceneGroup extends SceneParent, specifying T as SceneComponent
The function I am trying to implement is getVisibleChildren. Given a viewport, I want a receive a set of SceneComponents that should be rendered.
SceneParents implementation is recursively called on all children:
template< class T >
void SceneParent< T >::getVisibleChildren(const util::Camera& camera,
std::vector< SceneComponent* >& visibleChildren) const {
if (!this->isVisible(camera)) {
return;
}
// Get ids into a flat container so the next loop can be parallelized.
std::vector< std::string* > childIds;
for (auto itr = this->children.cbegin(); itr < this->children.cend();
++itr) {
childIds.push_back(itr->first);
}
// TODO: parallelize this.
for (auto itr = childIds.cbegin(); itr < childIds.cend(); ++itr) {
this->children[*itr]->getVisibleChildren(camera, visibleChildren);
}
}
SceneGroups implementation adds all of its SceneComponents to the accumulator (the assumption being that if a group is visible, so are its components). So the SceneGroup node acts as the base case for the recursion:
void SceneGroup::getVisibleChildren(const util::Camera& camera,
std::vector< SceneComponent* >& visibleChildren) const {
if (!this->isVisible(camera)) {
return;
}
// If this group is visible, assume all of its components are as well.
for (auto itr = this->children.cbegin(); itr < this->children.cend();
++itr) {
visibleChildren.push_back(itr->second);
}
}
Now that you have made it to this point in my post, I'm assuming you are interested (at least mildly) in my real-world application, not just the compiler error it is causing. So, if you feel so inclined, please offer any advice about how I can improve my implementation of the scene graph / things I should be looking out for while working on this project.
The iterators of std::map<K, V> are bidirectional iterators. It doesn't make any sense to use the less than operator for bidirectional iterator. Just write your loop using the equality or inequality operator:
for (auto itr = things.begin(); itr != things.end(); ++itr) {
}

using the find function from algorithm on vector

I want to use the find function from the algorithm library on a vector object. The vector object is a vector of customers, (Customer is a class I made). I first ran it and it gave me an error in stl_algo.h. I search the web for it and I searched here for it too, I found a question here about it and I ran the same code, but I still got that error.
My code is here:
Header File:
#include <string>
#include <sstream>
#include <map>
#include <vector>
using namespace std;
enum Status {ACTIVE, INACTIVE};
class Customer {
private:
// ID Database class for storing customers' ids
class IdDB {
private:
friend class Customer;
// member field
static map <string, int> idList;
// member function
static int getNumber (const string &threeLetters) {
map<string, int>::iterator i = idList.find(threeLetters);
if (i == idList.end()) {
idList.insert(pair <string, int> (threeLetters, 0));
return 0;
}else{
return ++(i->second);
}
}
};
string id;
string name;
string address;
Status status;
void makeId () {
string threeLetters = name.substr(0, 3);
int idNum = IdDB::getNumber(threeLetters);
stringstream oss;
oss << threeLetters << idNum;
id = oss.str();
}
public:
Customer (const string&, const string&, const Status);
// Accessor Methods
string &getId ();
string &getName ();
string &getAddress ();
Status getStatus ();
// Mutator Methods
void setAddress (const string&);
void setStatus (const Status);
// Misc. Methods
void printStatus ();
// Equality Operator Overloading
friend bool operator == (Customer&, Customer&);
};
class CustomerDB {
private:
static vector<Customer> customersList;
public:
static void addCustomer (const Customer&);
static void deleteCustomer (Customer&);
};
Source Code:
#include <iostream>
#include <string>
#include <algorithm>
#include "Customer.h"
using namespace std;
map<string, int> Customer::IdDB::idList;
Customer::Customer (const string &cName, const string &cAddress, const Status cStatus) : name(cName), address(cAddress), status(cStatus) {
makeId();
}
// Accessor Methods
string &Customer::getId () { return id; }
string &Customer::getName () { return name; }
string &Customer::getAddress () { return address; }
Status Customer::getStatus () { return status; }
// Mutator Methods
void Customer::setAddress (const string &newAddress) { address = newAddress; }
void Customer::setStatus (const Status newStatus) { status = newStatus; }
// Misc. Methods
void Customer::printStatus () {
if (status == ACTIVE)
cout << "Active";
else
cout << "In-Active";
}
vector<Customer> CustomerDB::customersList;
void CustomerDB::addCustomer (const Customer &customer) {
customersList.push_back(customer);
}
void CustomerDB::deleteCustomer (Customer &customer) {
vector<Customer>::iterator i;
i = find(customersList.begin(), customersList.end(), customer); // getting error in here
}
// Equality Operator Overloading
bool operator == (Customer &cust1, Customer &cust2) {
return cust1.getId() == cust2.getId();
}
after building with Code::Blocks, I got this,
in header file stl_algo.h:
}
/// This is an overload used by find() for the RAI case.
template<typename _RandomAccessIterator, typename _Tp>
_RandomAccessIterator
__find(_RandomAccessIterator __first, _RandomAccessIterator __last,
const _Tp& __val, random_access_iterator_tag)
{
typename iterator_traits<_RandomAccessIterator>::difference_type
__trip_count = (__last - __first) >> 2;
for (; __trip_count > 0; --__trip_count)
{
if (*__first == __val) // error in here exactly getting a red block
return __first;
++__first;
if (*__first == __val)
return __first;
++__first;
if (*__first == __val)
return __first;
Thanks
EDIT: Here is the build log
Compiling: C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/algorithm:63:0,
from C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:5:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h: In function '_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Customer*, std::vector<Customer> >, _Tp = Customer]':
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:4403:45: instantiated from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<Customer*, std::vector<Customer> >, _Tp = Customer]'
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:42:66: instantiated from here
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:162:4: error: no match for 'operator==' in '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = Customer*, _Container = std::vector<Customer>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = Customer&]() == __val'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:162:4: note: candidates are:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_pair.h:201:5: note: template<class _T1, class _T2> bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:285:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:335:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:122:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_T1>&, const std::allocator<_T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:127:5: note: template<class _Tp> bool std::operator==(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2427:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2434:5: note: template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2448:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2460:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/streambuf_iterator.h:194:5: note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_tree.h:309:5: note: template<class _Val> bool std::operator==(const std::_Rb_tree_iterator<_Tp>&, const std::_Rb_tree_const_iterator<_Val>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_tree.h:846:5: note: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator==(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_map.h:877:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_multimap.h:795:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_vector.h:1273:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:46:6: note: bool operator==(Customer&, Customer&)
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:46:6: note: no known conversion for argument 2 from 'const Customer' to 'Customer&'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:4403:45: instantiated from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<Customer*, std::vector<Customer> >, _Tp = Customer]'
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:42:66: instantiated from here
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:166:4: error: no match for 'operator==' in '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = Customer*, _Container = std::vector<Customer>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = Customer&]() == __val'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:166:4: note: candidates are:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_pair.h:201:5: note: template<class _T1, class _T2> bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:285:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:335:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:122:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_T1>&, const std::allocator<_T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:127:5: note: template<class _Tp> bool std::operator==(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2427:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2434:5: note: template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2448:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2460:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/streambuf_iterator.h:194:5: note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_tree.h:309:5: note: template<class _Val> bool std::operator==(const std::_Rb_tree_iterator<_Tp>&, const std::_Rb_tree_const_iterator<_Val>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_tree.h:846:5: note: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator==(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_map.h:877:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_multimap.h:795:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_vector.h:1273:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:46:6: note: bool operator==(Customer&, Customer&)
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:46:6: note: no known conversion for argument 2 from 'const Customer' to 'Customer&'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:170:4: error: no match for 'operator==' in '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = Customer*, _Container = std::vector<Customer>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = Customer&]() == __val'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:170:4: note: candidates are:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_pair.h:201:5: note: template<class _T1, class _T2> bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:285:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:335:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:122:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_T1>&, const std::allocator<_T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:127:5: note: template<class _Tp> bool std::operator==(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2427:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2434:5: note: template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)
Process terminated with status 1 (0 minutes, 1 seconds)
50 errors, 0 warnings
You should work on your const correctness, the problem is that your equality comparator takes the arguments by non const reference, but the last argument to find is taken by const reference, which means that the compiler cannot use it there.
Incidentally, once you add the const there you will be forced to add const accessors to the data. Also, if your operator only uses the public interface there is no need to declare it as a friend
CodeBlocks may give errors about the stl files however they are not actually the errors. It shows the related stl file of your error.

C++ wait problem

I have a code like this
if (pid > 0) {
// Child
} else {
// Parent
}
while (wait() > 0) {}
And there are includes
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <ctime>
#include <sys/types.h>
But when i try to compiile it with g++ (g++ test.cpp -o test) a have an errors:
lab3.cpp: In function «int main(int, char**)»:
lab3.cpp:57:18: error: no match for «operator>» in «{0} > 0»
lab3.cpp:57:18: warning: candidates are:
/usr/lib/gcc/i686-redhat-linux/4.6.0/../../../../include/c++/4.6.0/bits/stl_pair.h:220:67: замечание: template<class _T1, class _T2> bool std::operator>(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/lib/gcc/i686-redhat-linux/4.6.0/../../../../include/c++/4.6.0/bits/stl_iterator.h:304:46: замечание: template<class _Iterator> bool std::operator>(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/lib/gcc/i686-redhat-linux/4.6.0/../../../../include/c++/4.6.0/bits/stl_iterator.h:354:47: замечание: template<class _IteratorL, class _IteratorR> bool std::operator>(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
/usr/lib/gcc/i686-redhat-linux/4.6.0/../../../../include/c++/4.6.0/bits/basic_string.h:2548:58: замечание: template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/lib/gcc/i686-redhat-linux/4.6.0/../../../../include/c++/4.6.0/bits/basic_string.h:2560:27: замечание: template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/lib/gcc/i686-redhat-linux/4.6.0/../../../../include/c++/4.6.0/bits/basic_string.h:2572:58: замечание: template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/lib/gcc/i686-redhat-linux/4.6.0/../../../../include/c++/4.6.0/bits/stl_vector.h:1303:77: замечание: template<class _Tp, class _Alloc> bool std::operator>(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
What i'm doing wrong?
Your includes pull /usr/include/bits/waitstatus.h indirectly, which defines a union wait. Since you don't have a declaration of the wait-function, C++ sees wait() as a constructor expression. This means wait()>0 calls for an operator>(const wait &,int) which does not exist of course. GCC's diagnostics aren't really helpful here. Add sys/wait.h to fetch a valid prototype for the wait function.
wait() is defined in sys/wait.h.
But there's probably something else going on there that we can't see with the code you posted.
Try changing that to:
while (::wait() > 0) ...
to make sure you're calling the wait() function from the global namespace and not some other class or construct imported from elsewhere.