you shoud use mem_fun()
instead of mem_fun_ref(),
it will work with pointers.
yves Baumes
2009-08-25 11:28:13
you shoud use mem_fun()
instead of mem_fun_ref(),
it will work with pointers.
When you say:
void TextBody::addComponent(DocumentComponent& comp)
{
container.push_back(&comp);
}
is the thing referred to dynamically allocated? If not, you will probably have problems, and if it is you should simply pass a pointer.
mem_fun_ref() calls a member on a reference object, mem_fun() calls a method through a pointer.
Therefore you will need to use mem_fun() like so:
textbody.cpp
void TextBody::print()
{
if (container.size() == 0)
return;
for_each(container.begin(), container.end(),mem_fun(&DocumentComponent::print));
}
Thanks for the help guys, I ended up using a for loop but changed it back to the for_each with mem_fun instead of mem_fun_ref after seeing your answers, works like a charm