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

相关推荐
程序员AlbertTu10 小时前
# Mantissa 使用教程 — Python 版与 C++ 版
c++·python·数值运算
孙启超10 小时前
【AI开发之Rust】第 13 课:async/await 与 tokio 异步运行时
开发语言·后端·rust
Am-Chestnuts11 小时前
DeepSeek内容转Word有哪几种方法?用DS随心转对比6条主流路径
开发语言·人工智能
大黄说说11 小时前
App 启动速度优化:冷启动从 3s 降到 800ms 完整实操
开发语言
Lazionr11 小时前
多态:从多种形态到运行时绑定
开发语言·c++
tryxr11 小时前
矩阵的几种基础变换
java·数据结构·算法·矩阵
mmmmath_311 小时前
LeetCode.028.找出字符串中第一个匹配项的
数据结构·算法·leetcode
别动我齐刘海11 小时前
ROS2 Jazzy + C++ 实战路线——ros2_control
c++·人工智能·python·opencv·机器学习·机器人·github
大黄说说11 小时前
iOS 列表滑动卡顿:UITableView / UICollectionView 深度优化实战
开发语言
Selvaggia11 小时前
DMD(Distribution Matching Distillation,分布匹配蒸馏)
算法