#include <functional>
#include <iostream>
using namespace std;
class test {
public:
  test(){ p = new int[10];}
 void print_info(double a)
  {
    cerr << a << endl;
  }
  ~test(){
    cerr << __LINE__ << endl;
    delete []p;
  }
private:
  int *p;
};
int main()
{
    test t;
    std::function<void(void)> f = std::bind(&test::print_info, t, 2.0);
    //std::function<void(void)> f = std::bind(&test::print_info, std::cref(t), 2.0);
    return 0;
}
它会崩溃,因为test::~test()被调用了两次。但是,如果我替换t为std::cref(t)(或std::ref(t), &t),  ~test()则在退出 main() 时将只调用一次。
我没有弄清楚原因。我在 Ubuntu 12.04 64bit 上,使用 gcc 4.6.3。