在写平衡二叉树模板的时候碰到C2016错误,提示左操作数必须为左值
报错区域
else {
now->Left() = new node<T>(tar);//这一行报错了
now = nullptr;
return true;
}
left()方法实现
template<typename T>
node<T> * node<T>::Left() {
return left;
}
left是一个node类的指针,这个指针为什么不能当左值?
错误 C2106 “=”: 左操作数必须为左值
now->Left() = new node<T>(tar)
Left()是个函数啊,是不可以作为左值的。你可以先定义个left变量,等于now_Left(),然后再left = new node<T>(tar)