Jump to content
  • Advertisement
Sign in to follow this  
load_bitmap_file

std::bind2nd reference to reference issues

This topic is 4666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I have:
class Foo
{
public:
	void MemberFunction(const int& value) //int is used here, but this problem happens with any type
	{
	}
};

int main()
{
	std::list<Foo> aList;

	//assume aList gets filled up with elements or something

	std::for_each(aList.begin(), aList.end(), std::bind2nd(std::mem_fun(&Foo::MemberFunction), 5));

	return 0;
}


VS.Net 2003 gives me a "reference to reference" compiler error. If I make Foo::MemberFunction accept a value by copy instead of reference it compiles fine. Is there a way to make this work when I have the member function accept a reference using the STL? If not, what's the rationale behind it, and can boost::bind do this?

Share this post


Link to post
Share on other sites
Advertisement
If you look at the decleration of the binder2nd class, you will see that no, it is not possible the constructor in question being:

binder2nd(
const Operation& _Func,
const typename Operation::second_argument_type& _Right
);

As you can see, the second argument is a reference type of the second argument of the function you pass, which will be a reference, and references of references are illegal.

As far as boost::bind goes, try it and see.

Share this post


Link to post
Share on other sites
Quote:
Original post by Washu
If you look at the decleration of the binder2nd class, you will see that no, it is not possible the constructor in question being:

binder2nd(
const Operation& _Func,
const typename Operation::second_argument_type& _Right
);

As you can see, the second argument is a reference type of the second argument of the function you pass, which will be a reference, and references of references are illegal.

As far as boost::bind goes, try it and see.


Darn. Surely this makes std::bind2nd really rather limited? Oh well, boost::bind does this fine.

Share this post


Link to post
Share on other sites
Quote:
Original post by load_bitmap_file
Darn. Surely this makes std::bind2nd really rather limited? Oh well, boost::bind
does this fine.


It's known technical issue in the current standard itself that will be resolved, boost provides exact equivalents of the standard library function object adaptors and member function adaptors (like boost::bind2nd) that resolve these issues check Boost.Functional (not boost::function). However none of them are as powerful, flexible as boost::bind & placeholders, boost::bind even gives a uniformity which is always a plus.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!