C++ Lambda Expressions via Functor

Description

C++ Lambda Expressions via Functor

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

class MyFunctor/*from   ww  w  . ja  va 2 s .co m*/
{
public:
    void operator()(int x)
    {
        cout << x << endl;
    }
};

void ProcessVector(vector<int>& vect)
{
    MyFunctor Func;
    for_each(vect.begin(), vect.end(), Func);
}

int main()
{
    vector<int> myV;
    myV.push_back(1);
    myV.push_back(2);
    myV.push_back(3);
    myV.push_back(4);

    ProcessVector(myV);
}



PreviousNext

Related