我目前实现的二叉树输出方法在g++中出现了错误,大致如下:
Conditional jump or move depends on uninitialised value(s)
我的当前实现方案是:
void Foo::output(ostream &s, const Node *p)
{
if( p )
{
output( s , p -> left );
s << p -> info;
output( s , p -> right );
}
}
节点是一种基本结构,具有左右指针和一个整数信息变量。
输出流就是cout。
错误消息非常直接,它不喜欢我让它“跑掉”。
我的问题有两个方面:
1.为什么这样做是不恰当的?没有任何东西被改变,我不知道它会造成什么伤害。
2.正确的方法是什么?
谢谢。