4.Boost之ref
1.Boost之ref,案例:
#include<iostream>
#include <vector>
#include <boost/bind.hpp>
#include <boost/function.hpp>
?
using namespace std;
using namespace boost;
?
void print(std::ostream &os,int i)
{
??? os << i << endl;
}
?
void main()
{
??? //不可以拷貝的對(duì)象可以用ref的方式,入下面cout是系統(tǒng)的對(duì)象
??? //print中的第一個(gè)參數(shù)是ostream,引用系統(tǒng)的cout,所以用boost::ref(cout)
??? boost::function<void(int)> pt = boost::bind(print, boost::ref(cout), _1);
??? vector<int> v;
??? v.push_back(11);
??? v.push_back(12);
??? v.push_back(13);
?
??? //下面的pt只需要在傳遞一個(gè)參數(shù)即可,通過(guò)迭代的方式傳入一個(gè)參數(shù)的
??? for_each(v.begin(), v.end(), pt);
?
??? std::cin.get();
}
?
?
?
總結(jié)
以上是生活随笔為你收集整理的4.Boost之ref的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 3.Boost之function
- 下一篇: 6.Boost之smartpointer