I've been working with a doubly-threaded BST in C++, and I thought it would be cool to separate my visitor functions from my various traversals. However I can't figure out how to properly pass references to member functions into my traversal functions. Here is a massively simplified version of my problem:
class foo {
public:
foo() {};
~foo() {};
void print(int x) const { //visitor
cout << x << endl;
}
void traverse(void (*visitor)(int)) { //traversal
for (int i = 0; i < 9; i++)
visitor(myAry[i]);
}
void printAll() { //function calling the traversal and passing it a reference to the visitor
traverse(&print);
}
int myAry[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
};
The problem of course comes in the traverse(&print);
statement.
Any clues what's going wrong, or what I could try differently to achieve the same effect?