1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
// 6 different functions, all with different parameter lists
void a(sf::Vector2f);
void b(int);
void c();
void d(int,int);
void e(int,sf::Vector2f);
class MyClass
{
public:
void member(int);
};
///////////////////////////////
// bind them all to the same function type:
MyClass obj;
std::function<void()> func[6] = {
std::bind( &a, sf::Vector2f(16,5) ),
std::bind( &b, 3 ),
std::bind( &c );
std::bind( &d, 1, 2 ),
std::bind( &e, 8, sf::Vector2f(9,10) ),
std::bind( &MyClass::member, &obj, 42 )
};
func[0](); // calls: a( sf::Vector2f(16,5) );
func[1](); // calls: b( 3 );
func[2](); // calls: c();
func[3](); // calls: d( 1, 2 );
func[4](); // calls: e( 8, sf::Vector2f(9,10) );
func[5](); // calls: obj.member( 42 );
| |