1. 程式人生 > >boost::bind 詳解及常見問題

boost::bind 詳解及常見問題

// 7.1 MSVC 6.0編譯器
在函式簽名中不支援const:(移除const就可以了)
int f(int const);


int main()
{
    boost::bind(f, 1);     // error
}
// 7.2 MSVC 7.0以下編譯器
(1) 如果通過using宣告引入boost::bind,如:using boost::bind,那麼bind<R>(f, ...)語法將不能工作。
解決辦法為直接使用限定名boost::bind或者使用using指令:using namespace boost;
(2) 一個巢狀的命名為bind的類模板將隱藏函式模板boost::bind,使得bind<R>(f, ...)語法不能工作。
(3) MSVC將可變引數中的省略號看作一種型別,因此,其可以接受如下形式:
bind(printf, "%s\n", _1);
但是拒絕正確的形式如:
bind<int>(printf, "%s\n", _1);