I'm trying to use std::for_each() instead of a normal for loop as a practice, but I can't pass a member function to for_each().
Here is the code:
class Class
{
public :
void func (int a)
{
cout << a * 3 << " ";
}
}ob1;
int main()
{
int arr[5] = { 1, 5, 2, 4, 3 };
cout << "Multiple of 3 of elements are : ";
for_each(arr, arr + 5, ob1);
}
It works only if this member function is void operator() (int a). I don't know why any other member function cannot be passed into for_each()!