0

It's my first time to use functor. So hope can get some guide here. My program need to call different function depend on input. so i thinking to use functor to do that.

e.g.

main.cpp

```
#include "functor.h"
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
//do get input and switch case to call ex_functor with different functor parameter
//
//e.g. one of the case is this ex_functor
ex_functor( ret1, 5, 2);
cin.get();
return EXIT_SUCCESS;
}
```

functor.h

```
#ifndef FUNCTOR_H_INCLUDED
#define FUNCTOR_H_INCLUDED
int ret1 (int a, int b);
int ret2 (int a, int b);
int ret3 (int a, int b);
int ex_functor (int (*functor)(int a, int b), int a, int b);
#endif // FUNCTOR_H_INCLUDED
```

functor.cpp

```
#include <cstdlib>
#include <iostream>
#include "functor.h"
using namespace std;
int ret1 (int a, int b)
{
cout<<a+b;
return a+b;
}
int ret2 (int a, int b)
{
cout<<a-b;
return a-b;
}
int ret3 (int a, int b)
{
cout<<a*b;
return a*b;
}
int ex_functor (int (*functor)(int a, int b), int a, int b)
{
(*functor)( a, b);
return 0;
}
```

I'm using code::blocks10.05, the error is undefine reference to 'ret1(int, int)' at main.cpp line 9