std::inner_product in class template

Hi!

I encounter a problem when I tried to use inner product inside the class (I need to subtract the absolute values of two vectors). I cannot pass my own binaryOperaton function as an argument to inner_product(...) when this binaryOperation is defined inside the class.

My class look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
template <int dim>
class Convergence
{
    public:
// ...other stuff ...
    double myaccumulator(double x, double y)
    {
	return x + std::abs(y);
    }

    double myproduct(    double x, double y)
    {
	return x - y;
    }

    double calculate_differences(std::vector<double> vect1,
                                 std::vector<double> vect2)
    {
      return std::inner_product(std::begin(vect1),
                                std::end(vect1),
                                std::begin(vect2),
                                0,
                                myaccumulator,
                                myproduct);
    }
// ... other stuff ...
}


The following error appears:
error: invalid use of non-static member function ‘double Convergence<dim>::myaccumulator(double, double) [with int dim = 2]’

Can someone tell me what is incorrect in this implementation?
Last edited on
Declare the functions myaccumulator and myproduct as static since they don't rely on class data.
Yes, that works! Thank you very much!
Topic archived. No new replies allowed.