I've been reading a textbook on elementary data structures just for a review - it's been a while since I've written my own hash table or red/black tree :)
Anyway, I ran into something that threw me a little. The author is pretty intent on using the initializer list for every member (as one would hope), but in this one case where he is passing a function pointer to a hashing function, he opts to use the assignment operator in the constructor rather than setting up the pointer in the initializer list (and he is using the initializer list in this code as well):
template<class DataType>
HashTable<DataType>::HashTable(int (*hf)(const DataType&), int s)
: table(s)
{
hashfunc = hf;
}
where:
int (*hashfunc)(const DataType&);
is a private member.
I was wondering if there's some explicit reason for this choice, and if there's a pitfall he glazed over here - or if it's just a random lapse of thought. Function pointers can have an interesting syntax, and I was basically wondering if it causes a problem in this area.
No, there is no reason why it can't be initialised in the initialiser list.
It's perhaps possible that a buggy compiler might get confused and interpret initialisation in the list as a function call (since the syntax is similar); perhaps that's the explanation.