VS 2005环境下使用boost ::bind的一个注意事项

 

作者:朱金灿

来源:http://www.cnblogs.com/clever101

 

最近使用boost库,发现在VS 2005环境下使用boost ::bind使用错误就会引起编译器崩溃。比如下面程序:

#include <boost/bind.hpp>

class Test
{
public:
void operator()(bool f){}
};

int main()
{
Test n;

// this line crashes the compiler
boost::bind(&Test::operator(), &n);

}

        Win XP sp2+VS 2005 +sp1环境下编译时会导致编译器崩溃同时出现一个发送错误给微软的对话框。其实上面的程序对boost ::bind使用不正确,对于类的非静态成员函数绑定.A::funcn个参数, bind 要有 n+2 个参数:指向成员函数fun的指针, 绑定到this的对象, n个参数(程序中就是缺少函数的参数,如果不填参数,则需要添加占位符),但这不应该成为编译器崩溃的理由。看来VS 2005对函数模板的支持还不够啊!




posted @ 2009-09-24 22:07  是金子就会灿烂  阅读(320)  评论(0编辑  收藏  举报