b=a->b 在一类列表中是什么意思?
What does b=a->b means in a class of list?
在一类列表中b=a->b是什么意思?
我正在阅读的例子是列表的析构函数,在它的"while"循环中有这个操作。
Clistint::~Clistint(){
Clist *actual, *next;
if(head!=NULL){
actual=head;
while(actual!=NULL){
next=actual->next;
delete actual;
actual=next;
}
}
}
EDIT(现在您已经发布了代码)
next=actual->next;
delete actual;
actual=next;
这将把actual
设置为actual.next
。你不能只做
actual=actual->next;
因为这将是内存泄漏(您永远不会删除旧的actual
)。而且,你不能只写
next=actual.next;
因为actual
是一个指针。因此你必须得到它所指向的东西,比如
next=(*actual).next;
但是->
运算符就是这样做的,所以你可以直接做
next=actual->next; // means the same thing as "next=(*actual).next;"
(早前发布的文章)
和
意思相同b = (*a).b;
将局部变量b
设置为指针a
的b
的值。例如:
MyClass *a = new MyClass;
// do stuff with *a
int b;
b = a -> b; // gets the `b` value of `a` (assuming MyClass has a public int b)
// same as "b = (*a).b;"
a
是指向结构体或类的指针,a->b
是该结构体或类中的某个东西,可能是一个变量。还有一个名为b
的局部作用域变量,它被赋值为结构体a
中b
的值。如果没有看到完整的代码,很难说更多。
首先,=
和->
是c++语言的基本内置运算符。这些操作符的含义可以在任何有关C或c++的书籍中找到。
=
和->
都是可重载的操作符,这意味着如果不知道a
和b
是什么,就无法确定b = a->b
的确切含义。
相关文章:
- Pybind11:将元组列表从Python传递到C++
- 从链接列表c++中删除一个项目
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- C++如何通过用户输入删除列表元素
- 读取文件的最后一行并输入到链接列表时出错
- 复制列表初始化的隐式转换的等级是多少
- LNK2038、MSVS2017 MAGMA的原因列表
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 没有为自己的结构调用列表推回方法
- 使用简单类型列表实现的指数编译时间.为什么
- 一对向量构造函数:初始值设定项列表与显式构造
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- 通过for循环使用用户输入填充列表
- C++:如何使函数只返回作为列表一部分的字符串
- 概念中的cv限定符需要表达式参数列表
- 下面是我为检测链接列表中的循环而制作的代码
- 建议在运行时将带有类实例的列表从c++导入qml
- 让构造函数在其初始化列表中调用同一类的另一个构造函数是否有效
- b=a->b 在一类列表中是什么意思?
- 初始化列表——可以用同一类的其他成员初始化成员吗?