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

相关推荐
CoderCodingNo5 分钟前
【GESP】C++五级真题(结构体排序考点) luogu-B3968 [GESP202403 五级] 成绩排序
开发语言·c++·算法
想做后端的小C22 分钟前
Java:接口回调
java·开发语言·接口回调
YGGP1 小时前
【Golang】LeetCode 32. 最长有效括号
算法·leetcode
麒qiqi1 小时前
理解 Linux IO 多路复用
开发语言·数据库
MediaTea2 小时前
Python:模块 __dict__ 详解
开发语言·前端·数据库·python
自然常数e2 小时前
字符函数和字符串函数
c语言·算法·visual studio
leaves falling2 小时前
c语言分数求和
算法
Das12 小时前
【机器学习】01_模型选择与评估
人工智能·算法·机器学习
代码or搬砖2 小时前
HashMap源码
开发语言·python·哈希算法