back_inserter

Hello forum,

I am getting error with the following STL function:

 
back_inserter(...);


This is how i am doing it :

1
2
3
4
5
6
7
8
9
10
11
12
13

   std::vector<Photon*> m_photonPoints;

  .....................

  .....................
  //copy the contents of the photon
  //photonPoints is just another vector that we get as const reference 
  m_photonPoints.reserve(photonPoints.size());

  copy(photonPoints.begin(),
       photonPoints.end(),
       back_inserter(m_photonPoints.begin()));


And i am getting the following error:

1
2
3
4
5
6
7
8
9
g++  -fopenmp -std=gnu++0x -O2 -g -o bvhaccelerator.o -c bvhaccelerator.cpp -I/usr/include/OpenEXR 
bvhaccelerator.cpp: In member function ‘void BVHAccelerator::buildForPhotonPoints(const std::vector<Photon*>&)’:
bvhaccelerator.cpp:1047:44: error: no matching function for call to ‘back_inserter(std::vector<Photon*>::iterator)’
bvhaccelerator.cpp:1047:44: note: candidate is:
/usr/include/c++/4.6/bits/stl_iterator.h:473:5: note: std::back_insert_iterator<_Container> std::back_inserter(_Container&) [with _Container = __gnu_cxx::__normal_iterator<Photon**, std::vector<Photon*> >]
/usr/include/c++/4.6/bits/stl_iterator.h:473:5: note:   no known conversion for argument 1 from ‘std::vector<Photon*>::iterator {aka __gnu_cxx::__normal_iterator<Photon**, std::vector<Photon*> >}’ to ‘__gnu_cxx::__normal_iterator<Photon**, std::vector<Photon*> >&’
In file included from /usr/include/c++/4.6/algorithm:63:0,
                 from bvhaccelerator.cpp:2:



Any idea folks?

//Sajjad
as the error message said, back_inserter doesn't take an iterator, it takes a container. Also, vectors know how to append other vectors efficiently, use vector.assign or vector.insert, and you won't have to reserve explicitly
Last edited on
Use

back_inserter(m_photonPoints);

instead of

back_inserter(m_photonPoints.begin()));
back_inserter expects an container aka a vector item, vector.begin() returns an iterator or a int. Just remove the .begin();
Topic archived. No new replies allowed.