+ 3
How to assign a pointer to function?
we define a pointer to function using typedef keyword. we define a function with deafault argument and return type with define keyword and name as pointer
1 Resposta
0
//c++ hash table function pointer
//function
int hash(const Obj & obj){
return obj.value%n;
}
//hash table dec.
ht<dataType> mTable(hash, n);
//private members in ht
ADT<ADT<dataType> > table;
int(*hashfun)(const dataType &);
//constructor
ht<dataType>::ht(int(*hf)(const dataType &),
int s):table(s){
hashfun = hf;
}
hope this helps!