I was thinking I had to do that as well.
What I'm now thinking is that in the algorithms class I would make a basic shell class with a virtual overloaded function call operator like this
Code:
class funCallback
{
string name;
public:
funCallback(string label) : name(label) {}
string getName() { return name; }
virtual ~funCallback() {}
};
class cosCallback : public funCallback
{
public:
cosCallback(): funCallback("cos") {}
float operator()(int a) { return cos(a); }
};
class sinCallback : public funCallback
{
public:
sinCallback(): funCallback("sin") {}
float operator()(int a) { return sin(a); }
};
Then when building the function they would go into an array of funCallback pointers.
The only thing is I'm getting funky output when trying to call the operator
Code:
std::vector<funCallback*> a;
a.push_back(new cosCallback());
a.push_back(new sinCallback());
int val = 4;
for(int i = 0; i < a.size(); ++i)
{
funCallback* current = a.at(i);
std::cout << current->getName()
<< "(" << val << ")="
<< *current(val) //49: error: `current' cannot be used as a function
<< std::endl;
}