I'm experimenting with c++ as an excerise. I'm implementing a template class "MioVettore" that implements different reordering algorithms.
I'm implementing ShellSort and I want to be able to tell what kind of numerical series to use. To do that I thought it was a good a idea to assign a different function to a function pointer depending on the option selected by the user.
template <class T>
class MioVettore
{
private :
std::vector<T> data;
int SerieKnuth(const int &h) {
return h * 3 + 1;
}
int SerieSequenza(const int& h) {
return 0;
}
int SerieSedgewick(const int& h) {
return 0;
}
public:
MioVettore() {};
enum SerieType { KNUTH, SEQUENZA, SEDGEWICK };
void ShellSort(SerieType t) {
int (*evaluateH) (const int&);
switch ((int)t)
{
case (int)KNUTH:
evaluateH = SerieKnuth;
break;
case (int)SEDGEWICK:
evaluateH = SerieSedgewick;
break;
case (int)SEQUENZA:
evaluateH = &SerieSequenza;
break;
default:
std::cout << "valore serie non riconosciuto" << std::endl;
return;
}
/* ... */
}
When I try to assign a function to evaluateH
I got some errors that I have a hard time understanding, like:
'operator' : illegal operation on bound member function expression
The compiler found a problem with the syntax to create a pointer-to-member.
As I know a function pointer is defined as,
int f(int a) {return a;}
int (*pf) (int) = f;
So I can't understand where is the error.