You need to enable JavaScript to run this app. C++删除Block类子节点触发标量删除错误,改用std::shared_ptr仍无效
优惠活动
大模型
产品
解决方案
定价
更多

C++删除Block类子节点触发标量删除错误,改用std::shared_ptr仍无效

Block类子节点删除功能开发与故障记录

开发过程概述

  • 正在推进的开发目标:为C++自定义Block类实现子节点删除功能
  • 实现迭代过程:
    • 最初尝试基于原始指针实现删除逻辑,运行失败并触发标量删除错误
    • 后续切换为std::shared_ptr方案实现,原有故障仍未解决
  • 基础配置信息:
    • 存储子节点的成员变量children类型为std::vector<std::shared_ptr<Block>>
    • 调试观测结论:用于匹配目标节点的ptr变量可被正常定位,故障触发点位于删除流程的最后执行阶段,同样触发标量删除错误

现存功能实现代码

子节点移除方法

void Block::remove(Block* block)
{
    std::shared_ptr<Block> ptr(block);
    auto it = std::find(children.begin(), children.end(), ptr);

    if (it != children.end())
    {
        *it = NULL;
        children.erase(it);
    }
}

类析构函数实现

Block::~Block()
{
    for (auto& child : this->children)
    {
        child = NULL;
    }

    if (!this->children.empty())
        this->children.clear();
}

补充说明

  • 项目完整代码可在对应开源代码仓库中查阅,所有Block类相关函数的定义均位于AOLGuiLibrary/source/Block.cpp文件内

内容的提问来源于stack exchange,提问作者Sherlock Holmes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.12 05:54:06