<分区>
在我的讲座中,我没有看到有人使用析构函数将值重置为起始参数,而是在函数中手动处理每个变量。在类函数中使用析构函数进行重置/删除是否会导致任何问题
我的意思的小例子:
class Test1{
private:
int *test;
bool valid;
public:
Test1(int value,bool valid=false){
test=new int(value); this->valid=valid;
}
~Test1(){
delete test; test=nullptr; valid=false;
}
void ResetStats(int NewValue){
this->~Test1();
test1=new int(NewValue);
valid=false;
}
}