0

suppose you have the following method:

double * myMethod(double (*f)(double[]), double *x, int size)
{
    //do something and return
}

Why can't I write as follows?

double * myMethod(double (*f)(double *), double *x, int size)
{
    //do something and return
}

replacing the [] with * ?

Lanbo
  • 15,118
  • 16
  • 70
  • 147
stkhou
  • 183
  • 1
  • 2
  • 7
  • Why? There are better solutions, less complex and easier to understand and debug. – Ed Heal May 04 '12 at 08:53
  • Could you give some details about the compiler, its version and the error message you get? It works for me with gcc 4.6.3 – Tsvetomir Dimitrov May 04 '12 at 08:54
  • Somewhat of a tangent, but you shouldn't normally need to use function pointers in C++, except perhaps to interface to C code -- they're a horrible artifact inherited from the C language. Instead, use `std::function`, or templates and lambdas. – void-pointer May 04 '12 at 09:53

1 Answers1

1

You can, but because arrays deprecate the pointers, they actually have the same signature, so if you're getting an error it's because you're trying to redefine the function:

http://ideone.com/E1Z7B works because I renamed the second function.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625