Hello!
I have implemented the iterator_facade for a base class called DataObject.
So now I am
able to write things like this:
boost::shared_ptr<PxyFileData> file(...);
const DataObject& points = file->GetPoints();
int num_points = std::distance(points.begin(), points.end()); //! random
access iterator
A DataObject acts like a tree structure. Each DataObject holds a vector of
pointers to
children, which are also DataObjects.
Now to my problem: A PxyPoint is a sub class to DataObject, and
PxyFileData::GetPoints()
returns a DataObject where all the children are PxyPoint's. Now I would like
to call a
member function, PxyPoint::PutSpCode(const char*), on each of the children,
like this:
void put_sp_code(DataObject&, const char*);
void test()
{
shared_ptr<PxyFileData> file(...);
DataObject& points = file->GetPoints();
put_sp_code(points, "spcode");
}
void put_sp_code(DataObject& points, const char* code)
{
std::for_each(points.begin(), points.end(),
std::bind2nd(std::mem_fun(&PxyPoint::PutSpCode), code));
}
This does not compile (VC 7.1):
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\algorithm(21): error C2664: 'binder2nd<_Fn2>::result_type
binder2nd<_Fn2>::operator ()(binder2nd<_Fn2>::argument_type & ) const':
cannot convert parameter 1 from 'DataObject' to
'binder2nd<_Fn2>::argument_type & '
with
[
_Fn2=mem_fun1_t