Opened 8 years ago

Last modified 8 years ago

#4359 new Bugs

boost bind doesn't work with inherited structures

Reported by: jia3ep@… Owned by: Peter Dimov
Milestone: Boost 1.44.0 Component: bind
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:


The following code gives an error in VC++2008, VC++2010, g++ 4.2.4:

#include <boost/bind.hpp>

struct Y {
	void reset() {};	

template<typename T1, typename T2>
struct my_pair {
	T1 first;
	T2 second;

template<typename T1, typename T2>
struct my_pair2 : my_pair<T1, T2> {};

typedef my_pair<int, Y> mypair_t;
typedef my_pair2<int, Y> mypair2_t;

int main()
	mypair_t t1;
	mypair2_t t2;

	boost::bind<Y&>( &mypair_t::second, _1 )( t1 ).reset();  // OK!
	boost::bind<Y&>( &mypair2_t::second, _1 )( t2 ).reset(); // error: cannot convert from 'const Y' to 'Y &'

	return 0;

Change History (1)

comment:1 Changed 8 years ago by Steven Watanabe

This is a result of mem_fn's logic for handling get_pointer. I'm somewhat hesitant to touch this, as it's rather easy to break older compilers.

Note: See TracTickets for help on using tickets.