天天看點

4.Boost之ref



1.boost之ref,案例:

#include<iostream>

#include

<vector>

<boost/bind.hpp>

<boost/function.hpp>

using

namespace

std;

boost;

void

print(std::ostream

&os,int

i)

{

os <<

i <<

endl;

}

main()

//不可以拷貝的對象可以用ref的方式,入下面cout是系統的對象

//print中的第一個參數是ostream,引用系統的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隻需要在傳遞一個參數即可,通過疊代的方式傳入一個參數的

for_each(v.begin(),

v.end(),

pt);

std::cin.get();