Search
 
SCRIPT & CODE EXAMPLE
 

CPP

functors in c++

//BISMILLAHIR RAHMANIR RAHIM

#include<bits/stdc++.h>
#define arr_size(x)   sizeof(x)/sizeof(x[0]);
#define el    '
'
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;

}

Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ remove last character from string 
Cpp :: what is c++ used for 
Cpp :: c++ structure 
Cpp :: tolower funciton in cpp 
Cpp :: c++ remove text file 
Cpp :: c++ split string by several space 
Cpp :: uses of gamma rays 
Cpp :: find index of element in array c++ 
Cpp :: time of a loop in c++ 
Cpp :: powershell get uptime remote computer 
Cpp :: how to split string in c++ 
Cpp :: c++ cast to type of variable 
Cpp :: team fortress 
Cpp :: push local branch to another remote branch 
Cpp :: how to declare a 2D vector in c++ of size m*n with value 0 
Cpp :: factorial loop c++ 
Cpp :: how to add external library in clion 
Cpp :: cpp mark getter as const 
Cpp :: a square plus b square plus c square 
Cpp :: c++ string split 
Cpp :: automatic legend matlab 
Cpp :: life the universe and everything solution c++ 
Cpp :: find in unordered_map c++ 
Cpp :: min element in vector c++ 
Cpp :: 31. Next Permutation leetcode solution in c++ 
Cpp :: Youtube backlink generator tool 
Cpp :: sum array c++ 
Cpp :: stl in c++ 
Cpp :: How to use jwt in login api in node js 
Cpp :: hello world cc++ 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =