LINUX.ORG.RU

Вопрос про boost bind


0

0

Ну не понимаю, почему этот код не компилируется...

#include <boost/bind.hpp>

using namespace boost;

int f(int a, int b)
{
return a + b;
}

int main()
{
boost::bind(f, _1, _2)(1, 2);
return 0;
}


Я тоже не знаю, но так компилируется:

#include <boost/bind.hpp> #include <boost/function.hpp>

static int f(int a, int b) { return a + b; }

int main() { boost::function<int (int, int)> ff = boost::bind(&f, _1, _2); ff(1, 2); return 0; }

vasirck
()

#include <boost/bind.hpp>
#include <boost/function.hpp>

static int f(int a, int b)
{
    return a + b;
}

int main()
{
    boost::function<int (int, int)> ff = boost::bind(&f, _1, _2);
    ff(1, 2);
    return 0;
}

vasirck
()

http://boost.org/libs/bind/bind.html#Limitations
bind принимает аргументы по non-const ref.

вот так будет компилироваться.
#include <boost/bind.hpp> 

int f(int a, int b) { 
	return a + b; 
} 

int main() {
	int a = 1, b = 2;
	boost::bind(f, _1, _2)(a, b);
	return 0; 
}

AnToXa
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.