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次;

相关推荐
Zhou14113622 分钟前
SpringSecurity_02_授权与高级功能
开发语言·python
千里码aicood1 小时前
基于CART算法的图书分类系统设计与实现
数据库·算法·分类
码匠许师傅1 小时前
【C++三方组件】cpp-httplib:一个头文件起 HTTP 服务
开发语言·c++·http
做cv的小昊1 小时前
【World Model】π0.5:a Vision-Language-Action Model with Open-World Generalization
人工智能·算法·机器学习·大模型·多模态·vla·世界模型
لا معنى له2 小时前
World-In-World: World Models in a Closed-Loop World
算法
无名猿2 小时前
new/delete 与 malloc/free:为什么绝对不能混用
c++·内存管理·现代c++·踩坑记录
小小小小钰儿2 小时前
1.5-Python网络编程
开发语言·网络·python·web安全·计算机·网络安全
hiahiahia1232 小时前
实现完整 Tool Dispatcher
开发语言·前端