析构函数与函数返回执行的顺序问题

//===============================
// Name        : test.cpp
// Author      : trialley
// Date        : 2019.5.6
// Copyright   : MIT
// Description : 
//===============================

#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
using namespace std;

class test {
public:
	test(int i) {
		cout << "con" << endl;
	}
	~test() {
		cout << "dis" << endl;
	}
};

int func() {
	test a(1);

	return 0;
}

int main() {
	func();
	return 0;
}

对析构函数和return打断点,可以发现是先返回值后调用析构函数。

上一篇:记录一个url_for的用法


下一篇:Nginx学习之如何搭建文件防盗链服务的方法示例