为什么一个对象被发送到这个函数中,但从未被使用
Why is an object sent into this function, but is never used?
int height(const Tree& T, const Position& p) {
if (p.isExternal()) return 0; // leaf has height 0
int h = 0;
PositionList ch = p.children(); // list of children
for (Iterator q = ch.begin(); q != ch.end(); ++q)
h = max(h, height(T, *q));
return 1 + h; // 1 + max height of children
}
我的教科书给出了上面的代码来查找一般树的高度。为什么"树T"发送到函数,如果它从来没有使用(它的成员函数/变量从来没有调用或使用)在整个函数?
我想这是为了与其他函数保持某种一致性。例如,函数depth
可能通过从树的根开始,并使用DFS找到该位置来计算位置的深度。
相关文章:
- 为什么我不能将一个对象push_back到属于另一个类的对象向量中?
- 为什么C++在将一个对象复制到另一个对象时需要对这两个对象进行低级常量限定
- 为什么我可以在不重载 "=" 运算符的情况下将一个对象分配给另一个对象?
- 为什么我可以使用 memcpy 将一个对象变量复制到另一个对象变量
- 我重载了 << 和 = 运算符。为什么当我将一个对象分配给另一个对象并尝试打印它时,我会被打印出来?
- 为什么将两个对象分配给另一个对象后,两个对象不一样?
- 为什么数组中对象的析构函数在被另一个对象替换时不被调用?
- 为什么我们需要在堆中创建一个对象
- 为什么在 C++ 中,当对象包含在另一个对象中时,复制构造函数被调用两次
- 只有当声明一个对象时,内存空间才会分配给类的数据成员,那么为什么 Sizeof(class_name) 给我结果
- 为什么引用可能是一个对象
- 为什么我可以分配一个对象数组,但不能将它们放在向量中
- 为什么在 const 对象上调用 std::move 在传递给另一个对象时会调用复制构造函数
- 为什么我不能初始化一个对象,并将自身合并到它的 c++ 中?
- 为什么我可以捕获一个对象或dynamic_cast,即使它的std::type_info对象不同
- 当用于初始化另一个对象时,为什么要按值传递参数
- 为什么我的对象无法访问在公共基类中定义的另一个对象的受保护成员?
- 为什么一个对象在被推入容器时会失去多态性
- 如果一个引用一旦被初始化为一个对象,它就不能被改变,为什么这样做呢?
- 为什么一个对象被发送到这个函数中,但从未被使用