2
2boxers
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
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