Jon Stewart on 2 Jun 2003 21:05:01 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [ALACPP] boost binding a const ref?


> So, if I have code that looks like this:
> 
> class Foo
> {
> 	void doSomething(SomeType const& param)
                         ^^^^^^^^^^^^^^^^^^^^^

Should be "const SomeType& param".

You want a reference to a const object, not a const reference to an 
object.

"Const reference" is a convenient misnomer for reference to a const 
object; references -- unlike pointers -- are implicitly const.


> 	{
> 		// do Something
> 	}
> };
> 
> and some more code that looks like this:
> 
> ...
> 
> Foo thing;
> 
> MyDoSomethingPtr = boost::bind<SomeType const&>(&Foo::doSomething, this, 
                                 ^^^^^^^^^^^^^^^

You shouldn't need this, unless your compiler is dumber than VC6.


> _1);


What type is MyDoSomethingPtr?

Also, remember that references can bite you in the ass when using bind. 
You may want boost::ref or boost::cref. I.E.,

MyDoSomethingPtr = boost::bind(&Foo::doSomething, this, boost::cref(_1));



Jon
-- 
Jon Stewart
stew1@xxxxxxxxxxx
_______________________________________________
alacpp mailing list
alacpp@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/alacpp