
-----------------------------------
Clayton
Wed Nov 29, 2006 6:56 pm

Pointer Issues
-----------------------------------
Hey guys, I was reading through some C++ tuts, and I was fine until I hit pointers, (well I understand so far, but this program has me stumped). This is a chunk of code that was on there, and I didn't understand what was going on, so I decided to cut, paste and compile to see what the output was, and it didn't even work! So now I'm trying to figure out why, but I'm not getting anywhere. Any help on where and why this isn't working would be great. The error I'm getting from my compiler is this:

pointtest.cpp: In function 'int main()':
pointtest.cpp:24: error: 'minus' undeclared (first use this function)
pointtest.cpp:24: error: (Each undeclared identifier is reported only once for each function it appears in.)

and heres the code :


// pointer to functions
#include 
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 