在我的 C++ 数据结构课程中,我们正在研究二叉树。有些代码包含同时使用 & 和 * 的地方(彼此相邻),这非常令人困惑。
void balance( AvlNode * & t )
是使用 this 的函数定义的一个示例。这里的 * 和 & 会发生什么?
编辑:这个问题的答案告诉我,我真的对指针和引用一无所知,但来源都说了不同的事情,像这儿例如调用 * 解引用运算符。我在哪里可以在一处找到所有这些信息? (最好不在 stackoverflow 上)
Read from right to left1, reading &
as a "reference to [a|an]" and *
as a "pointer to [a|an]", so you get: "t is a reference to a pointer to an AvlNode".
1. For more complex cases, it's not always entirely right to left--it's from the name being declared outward to the type of the declaration. If you have multiple nested parentheses, you proceed right from name to a closing parenthesis, then left to the matching open parenthesis, then right from the place you last left off to the next closing parenthesis, and so on until you reach the outer-most level.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)