3
In solving some issues in C++, I came across the code:
class MinhaClasse{
private:
int a;
public:
MinhaClasse(int b){
a = b;
ImprimeA();
};
~MinhaClasse(){
IncrementaA();
ImprimeA();
};
void IncrementaA(){
a++;
};
void ImprimeA(){
printf("[%d]", a);
};
};
int main(){
MinhaClasse * mClasseD = new MinhaClasse(1);
MinhaClasse mClasseE(10);
return 0;
}
Exit:
[1][10][11]
However, when removing the destructor ~MinhaClasse()
, the exit becomes:
[1][10]
I read some concepts about destructor and some questions, about the theme, among them:
However I follow without understanding very well this code, why when the destroyer is removed my exit changes?
Got it Victor! Thank you very much! I’m going to take a look at Heap and Stack, thanks again
– Luiz Augusto