My problem is as follows : I have two classes, one is Tree, and another one is Node. As you may have understand, Tree performs operations using Nodes objects. As debug, I would like to use a Node << overload to display node content. For example :
class Tree {
(....)
void InsertNode(Node *node){
std::cout << node << std::endl; // I would like this to display for example node._data and other information
}
}
What I've tried is first the "classical solution" I've always worked with, putting << overload outside of Node Class, but Tree still does not call this function.
std::ostream& operator<<(std::ostream& os, Node &node)
{
os << "Node value here " << node.getData();
return os;
}
I have also tried to put it directly in Node class:
class Node
{
public:
(...)
std::ostream& operator<<(std::ostream& os)
{
os << "Node here " << getData();
return os;
}
}
But none of these solutions worked, the overload is not even called. Is it possible to perform such an action ? How can I do so ?
Thanks a lot by advance,