I've following class:
class A {
public:
// ctr and etc ...
A* clone(B* container);
};
Now, I've a vector<A*> availableObjs
populated already. I want to call clone
on each of those, so and insert cloned objects into a new container clonedObjs
of type vector<A*>
. I'm trying following - but it doesn't compile:
transform(availableObjs.begin(), availableObjs.end(), back_inserter(clonedObjs),
bind1st(mem_fun(&A::clone), container)); // container is of type B*
Is there a easy way out? I've a lot classed like A - so making each of those a functor is too much task.
You need to use
bind2nd
instead ofbind1st
:The functor created by
mem_fun(&A::clone)
expects anA*
as its first parameter. This is the normally implicitly specified instance on which the method is called. The first "real" parameter ofA::clone
is the second parameter ofmem_fun(&A::clone)
and therefore needs to be bound withbind2nd
.