Hi all!

I get the following error while trying to compile this code

/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_numeric.h:116: error: must use .* or ->* to call pointer-to-member function in `__binary_op (...)'

I am quite stunned because I've used before in a similar way

Can any body give me a hint?

Thank you in advance!

int main(void)
{
  // things happening
  std::vector< std::vector<double> > values(3, std::vector<double>());
  // fill values in values vector
  doIt(values);
}

void doIt(const std::vector< std::vector<double> > &values )
{
  // things happening
  double e = sqrt(std::accumulate(values[0].begin(), values[0].end(), 0.0, accumSq))/values[0].size();
  // things happening
}

double accumSq(double sum_so_far, double x)
{
  return sum_so_far + x*x;
}

Recommended Answers

All 5 Replies

I have just run it on Mac, didn't get any compilation error, what platform you are using?

#include <iostream>
#include <complex>
#include <functional>
#include <numeric>
#include <vector>
using namespace std;


double accumSq(double sum_so_far, double x)
{
  return sum_so_far + x*x;
}


void doIt(const std::vector< std::vector<double> > &values )
{
  // things happening
  double e = sqrt(std::accumulate(values[0].begin(), values[0].end(), 0.0, accumSq))/values[0].size();
  // things happening
}


int main(int argc, char *args[])
{
  // things happening
  std::vector< std::vector<double> > values(3, std::vector<double>());
  // fill values in values vector
  doIt(values);

  return 0;
}

If I put in declarations for each of the functions ( doIt and accumSq ) above main the example compiles just fine for me.

Is there a reason why you are using such an old compiler? I'm sure that red-hat has some more recent package of GCC available. And yes, you need the function AccumSq to be declared sometime before you use it.

I have just run it on Mac, didn't get any compilation error, what platform you are using?

In this red hat works like a charm
Linux hostname 2.6.18-238 #1 SMP Fri Jan 14 17:17:13 CET 2011 x86_64 x86_64 x86_64 GNU/Linux
gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)

Though in this one I get the compilation error
Linux hostname 2.6.9-89 #1 SMP Wed Jun 3 13:16:24 CEST 2009 i686 i686 i386 GNU/Linux
gcc version 3.4.6 20060404 (Red Hat 3.4.6-11)

If I put in declarations for each of the functions ( doIt and accumSq ) above main the example compiles just fine for me.

Getting the same error using for_each

I am confused, the difference the gcc version differs and the platform 64bits vs 32bits

Is there a reason why you are using such an old compiler? I'm sure that red-hat has some more recent package of GCC available. And yes, you need the function AccumSq to be declared sometime before you use it.

Actually is because of a matter of compatibility with other stuff, anyway I can't change the compiler

I think I will end up using a loop with an iterator even though it is not so neat

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.