Horje
functors in c++ Code Example
functors in c++
//BISMILLAHIR RAHMANIR RAHIM

#include<bits/stdc++.h>
#define arr_size(x)   sizeof(x)/sizeof(x[0]);
#define el    '\n'
using namespace std;


class myFunctor
{

private:
    int myObject;

public:

    myFunctor (int parameterVar = 0) // constructor
    {
        myObject = parameterVar;
    }

    /* the "operator" word is a keyword which indicates this function is an
       overloaded operator function. The () following this just tells the
       compiler that () is the operator being overloaded.  */

    int operator() (int myArgument)
    {
        return myObject + myArgument;
    }

};


int main()
{

    int array[5] = {1, 2, 3, 4, 5};

    transform(array, array + 5, array, myFunctor(100));

    int sz = arr_size(array)

     for (int i =0; i< sz; i++)
     {
         cout<<array[i]<<" "<<el;
     }

    return 0;

}





Cpp

Related
no template named vector in namespace std Code Example no template named vector in namespace std Code Example
sprintf add two xeroes for a float number Code Example sprintf add two xeroes for a float number Code Example
sort sub vector, sort range of vector c++ Code Example sort sub vector, sort range of vector c++ Code Example
how to use printf with <cinttypes> c++ Code Example how to use printf with <cinttypes> c++ Code Example
online c++ graphics compiler Code Example online c++ graphics compiler Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11