析构函数调用(堆栈)变量之间的赋值? [英] Destructor called on assignment between (stack) variables?

查看:191
本文介绍了析构函数调用(堆栈)变量之间的赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

matrix m1(5,5); 
matrix m2(5,5); 
m1 = matrix(m2); 

对于上述代码(对于任意类,矩阵),将析构函数调用与m1相关联,当m2的信息被复制到它?

For the above code (for an arbitrary class, matrix), will the destructor be called for the information associated with m1, when the information of m2 is copied over to it?

推荐答案

不,赋值操作符需要处理释放任何资源 m1 可以在执行分配之前保持。只有当 m1 即将超出范围时,析构函数才会被调用。

No, an assignment operator will need to deal with releasing whatever resources m1 may hold before performing an assignment. The destructor will be called only when m1 is about to go out of scope.

这篇关于析构函数调用(堆栈)变量之间的赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆