Hi, i have this data collection i which the nodes are linked by parent. meening multiple nodes can be connected to one parent. like in this http://i50.tinypic.com/2qtc1ad.png picture.
Each node has a method called foo(). now i want to call all foo()s through the root node. so i need to have the child node pass it's foo() to it's parents foo(), and the parent to pass his foo() to his parent foo() and so on and so forth until they all get to the root node's foo().
Is this possible in c++ and is it the right aproach?
i will add functionality to foo() later for name lets say it just prints out name.
so would it be possible to pass child's foo to it's parent's foo. like this maybe:
Rather than the messy solution of passing function pointers around, just so that each instance can call the same method in your parent, would it not be much better to have a base class that contains the method you want to call and then create child classes each can then still call the same method in the parent as long as it isn't private. If you want this method to be only available to the base class and all the derived classes then make it protected otherwise leave it public and everyone can then call it, if that's what you need.