У меня есть ошибка компиляции при использовании std:: function в шаблонизированной функции-члена, следующий код - простой пример:
#include <functional>
#include <memory>
using std::function;
using std::bind;
using std::shared_ptr;
class Test {
public:
template <typename T>
void setCallback(function<void (T, int)> cb);
};
template <typename T>
void Test::setCallback(function<void (T, int)> cb)
{
// do nothing
}
class TestA {
public:
void testa(int a, int b) { }
};
int main()
{
TestA testA;
Test test;
test.setCallback(bind(&TestA::testa, &testA, std::placeholders::_1, std::placeholders::_2));
return 0;
}
И придет следующая ошибка компиляции:
testtemplate.cpp: В функции 'int main():
testtemplate.cpp: 29: 92: ошибка: нет соответствующей функции для вызова 'Test:: setCallback (std:: _ Bind_helper) (int, int), TestA, const std:: _ Placeholder < 1 &, const станд:: _ Заполнитель < 2 > & > :: тип)
testtemplate.cpp: 29: 92: примечание: кандидат: testtemplate.cpp: 10: 7: note: шаблон void Test:: setCallback (std:: function)
testtemplate.cpp: 10: 7: note: аргумент шаблона вычет/замещение не удалось:
testtemplate.cpp: 29: 92: note: 'std:: _ Bind (TestA *, std:: _ Placeholder < 1 > , std:: _ Placeholder < 2 > ) > не выводится из 'std:: function
Я использую С++ 11 и g++ 4.7