有关成员函数const修饰,对传入的成员属性影响以及返回指针引用的bug问题
bool contains(_T& data, bn_ptr t)const
此时传入的成员参数是带有const属性的,但是data是不带const的,通过影响成员参数访问权限,而达到不能修改的目的;
BinarySearchTree<_T>& BinarySearchTree<_T>::operator=(const bst_ref bst)
{
if (this != &bst)
{
makeEmpty();
this->root = this->clone(bst.root);
}
return(*this);
}
上述代码中,之所以如return语句类型可以与函数返回类型不同的原因,是因为c++有返回值优化技术,此时对象直接作为返回值到调用点,而不是临时变量;
其他的情况,是需要严格匹配的;

浙公网安备 33010602011771号