P
Paul Jansen
Don't go away yet... this is a bit more complicated than 'how do I
take a method address'!
I have a class foo, and method foo::bar. I also have a tree of foo
objects, which I process recursively, in top-down or bottom-up passes.
When I traverse the tree and reach object X, I need to call X.bar().
'bar' is not static; it needs the data in the current object/node.
Furthermore, I have generic (recursive) functions to traverse the
tree. The generic function has a parameter, which is the name of the
object method to call when the generic function reaches a particular
node in the tree. So, if I want to do a top-down pass through the
tree, calling 'bar' at every node, I say:
topDownPass(&foo::bar);
And 'topDownPass' does something like this:
void foo:topDownPass(NodeFunction nfunc) {
(this->*nfunc)();
...
}
This code compiles and links Ok (on gcc), but I don't understand it
(and I haven't tested it yet). 'bar' is not static. Which 'bar' am I
taking the address of in the call 'topDownPass(&foo::bar)'? Does it
matter, since there is presumably only one instance of 'bar' anyway?
What will 'this' be inside 'bar'?
Or should I make 'bar' static, and pass in 'this' as a parameter?
Thanks -
/PJ
take a method address'!
I have a class foo, and method foo::bar. I also have a tree of foo
objects, which I process recursively, in top-down or bottom-up passes.
When I traverse the tree and reach object X, I need to call X.bar().
'bar' is not static; it needs the data in the current object/node.
Furthermore, I have generic (recursive) functions to traverse the
tree. The generic function has a parameter, which is the name of the
object method to call when the generic function reaches a particular
node in the tree. So, if I want to do a top-down pass through the
tree, calling 'bar' at every node, I say:
topDownPass(&foo::bar);
And 'topDownPass' does something like this:
void foo:topDownPass(NodeFunction nfunc) {
(this->*nfunc)();
...
}
This code compiles and links Ok (on gcc), but I don't understand it
(and I haven't tested it yet). 'bar' is not static. Which 'bar' am I
taking the address of in the call 'topDownPass(&foo::bar)'? Does it
matter, since there is presumably only one instance of 'bar' anyway?
What will 'this' be inside 'bar'?
Or should I make 'bar' static, and pass in 'this' as a parameter?
Thanks -
/PJ