Yes, I see what you're saying. The assignment doesn't allow me to alter the public portion of the class. So my Words and Definitions are in the private section. For this function I need to simply display all the words and definitions using the function pointer and only having what's in the private section to work with.
Even if I changed the arguments in the show_array function, I'd still need arguments to send from Main, so I'm not sure what I'm suppose to be doing.
It seems to me that what you are doing is implementing the visitor pattern for your dictionary, and while show_array could use forEach in its implementation, I don't see why forEach would use show_array.
I would expect forEach's definition to look something like:
1 2 3 4 5 6 7 8 9 10
void Dictionary::forEach( WordDefFunc func, bool forward )
if (forward == true)
for ( unsigned i=0; i<number_of_words; ++i )
func(word_def_array[i].word, word_def_array[i].define) ;
// do it in reverse.
When I said print_it was a free standing function, I meant that it was not a member of a class. The idea behind the visitor pattern is to allow code that isn't part of the class to manipulate or use data belonging to the class, within the confines of (in this case) the forEach method.