boost::bind with functions that have parameters that are references

Brian R. Bondy picture Brian R. Bondy · Jan 22, 2009 · Viewed 22.2k times · Source

I noticed that when passing reference parameters to boost bind, those parameters won't act like references. Instead boost creates another copy of the member and the original passed in variable remains unchanged.

When I change the references to pointers, everything works ok.

My question is:

Is it possible to get references to work, or at least give a compiling error when it tries to use reference parameters?

Answer

Timo Geusch picture Timo Geusch · Jan 22, 2009

The boost documentation for bind suggests that you can use boost::ref and boost::cref for this.