C++资源重复释放问题

这不是自己释放了2次;

可能是类互相引用,有类似现象释放资源时引起;还不太了解;

类对象作为函数参数也会引起;

下面是一个简单示例;

cpp 复制代码
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

class A{
    public:
	A()
	{
		std::cout<<"String A"<<std::endl;
	}

	~A(){
		std::cout<<"Ending Class A"<<std::endl;
	}
};

A a1;

void func(A a)
{
	return ;
}

int main(int argc,char **argv)
{
	func(a1);
	return 0;
}

从运行结果看,析构函数被调用了2次;

相关推荐
Joy T2 小时前
Agent 确定性上下文设计:从 Prompt 参数注入到能力分层
java·开发语言·微服务·架构·prompt·agent context
专注仿真5 小时前
引擎扩展性与集成设计深度剖析:从 14 个扩展点到 DIS→HLA 演进之路
开发语言·算法·仿真引擎·推演引擎
码爸5 小时前
支持向量机介绍与示例
算法·机器学习·支持向量机
怕浪猫5 小时前
2028编程圈很火的10个Skills
算法·面试·github
Best-Wishes5 小时前
科来网络分析系统(技术交流版)使用说明书
开发语言·junit·php
代码不停6 小时前
自动化测试(java)
java·开发语言·selenium·自动化
别动我齐刘海7 小时前
Linux 系统调试学习1
linux·运维·服务器·c++·学习·机器学习·机器人
鬼手点金8 小时前
opencode-rules 插件
java·开发语言·前端·人工智能·chrome·git·github
爱上网的小舟8 小时前
星际战士2启动错误怎么办?5种游戏报错解决方法
开发语言·php
阿里嘎多学长9 小时前
2026-10-12 GitHub 热点项目精选
开发语言·程序员·github·代码托管