Skip to content

Instantly share code, notes, and snippets.

@DamonHao
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save DamonHao/5768dd92de2e911da8bd to your computer and use it in GitHub Desktop.

Select an option

Save DamonHao/5768dd92de2e911da8bd to your computer and use it in GitHub Desktop.
boost bind copy parameter
/*
* test_bind.cc
*
* Created on: Aug 10, 2014
* Author: damonhao
*/
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
using namespace std;
typedef boost::shared_ptr<int> intPtr;
void haha(intPtr& a)
{
cout << a.use_count() << endl;
a.reset();
}
int main()
{
intPtr ptr(new int(1));
intPtr& ptr1 = ptr;
cout << ptr.use_count() << endl;
boost::function<void()> f1;
f1 = boost::bind(haha, ptr1);
f1();
cout << ptr.use_count() << endl;
return 0;
}
/*
output
1
2
1
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment