You really should use a virtual method for something like this. You can change your isLeafNode()
query to return a pointer to the leaf node if it is one, and NULL otherwise.
class LeafNode; // forward declare
class Node {
//...
public:
virtual ~Node () {}
virtual LeafNode * isLeafNode () { return 0; }
//...
};
class LeafNode : public Node {
//...
public:
LeafNode * isLeafNode () { return this; }
//...
};
Then, you can use this method from a Node
to access the data
if it is actually a LeafNode
.