【发布时间】:2021-12-30 11:02:40
【问题描述】:
我的问题与将指针分配给另一个指针有关。在下面的代码中的方法next_schedulable_operation()。成员变量candidates_ 具有mlir::Operation* 类型的元素。我有一个迭代器op_itr 指向candidates_ 中的一个元素。在从candidates_ 中删除元素之前,我使用代码行mlir::Operation* op = *op_itr; 制作了指针(?)的本地副本
然后在最后一行,我将局部变量分配给成员变量schedulable_op_ 与schedulable_op_ = op;
这会导致未定义的行为吗?我不能使用对象mlir::Operation,因为它说析构函数是私有的。
error: ‘mlir::Operation::~Operation()’ is private within this context
代码
【问题讨论】:
-
除非取消引用或删除,指针只是数字。例如,您复制了建筑物的地址卡,并销毁了原始地址卡,只要建筑物仍然存在,复制的地址卡就仍然有效。