help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pointer to function. why doesn't this compiler


From: 2boxers
Subject: pointer to function. why doesn't this compiler
Date: Thu, 27 May 2004 17:26:58 -0400

Can somebody tell me why the following program fails to compile?
I am using gcc-3.4.0.

#include <iostream>
using namespace std;

int addition (int a, int b)
{ return (a+b); }

int subtraction (int a, int b)
{ return (a-b); }

int (*minus)(int,int) = subtraction;

int operation (int x, int y, int (*functocall)(int,int))
{
  int g;
  g = (*functocall)(x,y);
  return (g);
}

int main ()
{
  int m,n;
  m = operation (7, 5, addition);
  n = operation (20, m, minus);
  cout <<n;
  return 0;
}

here is what i get when i try to compile:
g++ pointer4.cpp -o pointer4

pointer4.cpp: In function `int main()':
pointer4.cpp:23: error: `minus' undeclared (first use this function)
pointer4.cpp:23: error: (Each undeclared identifier is reported only
once for each function it appears in.)

It would seem to me that minus is being declared in line 10. i.e.
minus is being declared as a pointer to a function that accepts 2 int
arguments, returns type int, and is being assigned the address of
subtraction.

Thanks in advance for any suggestions,
ChasW


reply via email to

[Prev in Thread] Current Thread [Next in Thread]