Nov 13, 2011 at 1:02pm UTC
Dear all
I need some help in accessing a vector member by using iterator, the vector xb and d are of same dimension. I am trying following code but it is not working
....
std::vector<float>::iterator result;
std::vector<float> xb;
std::vector<float> d;
...
min_dis=5;
result =std::find(d.begin(), d.end(), min_dis);
...
float xbest;
xbest=xb.at(result);
.......
while running this code I am getting this error
error: no matching function for call to ‘std::vector<float, std::allocator<float> >::at(__gnu_cxx::__normal_iterator<float*, std::vector<float, std::allocator<float> > >&)’
/usr/include/c++/4.4/bits/stl_vector.h:650: note: candidates are: typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::reference std::vector<_Tp, _Alloc>::at(size_t) [with _Tp = float, _Alloc = std::allocator<float>]
/usr/include/c++/4.4/bits/stl_vector.h:668: note: typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::const_reference std::vector<_Tp, _Alloc>::at(size_t) const [with _Tp = float, _Alloc = std::allocator<float>]
Last edited on Nov 13, 2011 at 1:03pm UTC
Nov 13, 2011 at 2:44pm UTC
I found the mistake :)
it reuires following lies
int ax;
ax=(result - d.begin());
xbest=xb.at(ax-1);