Last active
August 29, 2015 14:05
-
-
Save DamonHao/5768dd92de2e911da8bd to your computer and use it in GitHub Desktop.
boost bind copy parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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