我有适用于 A 类的函数。A 类在构造函数中分配一些内存并在析构函数 A::~A() 中释放它。
现在如果。
A someFunc()
{
//This is just to illustrate that it is possible for that variable to be overwritten few times before returning.
A locA;
for(some condition)
{
//Something something
A forA(i);
//Something.
if(end) locA = forAj;
}
return locA;
}
这个好吗?每次在该 for 循环中再次创建该类时,是否都会调用该类的析构函数?