Suppose we have a struct named A declared this way:
struct A{
~A(){
cout << "destructor called" << endl;
}
}
and a main:
A create(){
A variableToReturn;
return variableToReturn;
}
int main() {
A var1 = create();
return 0;
}
is the destructor called even though we returned the variable from a function and so is the variable in main var1 defined or not? Same question arise if we return the variable from an operator such as:
A var1 = var2 + var3;