Life of an object created inside a button_click

I'm very suprised.
I have a button_click_command where I do the next:

1
2
3
4
5
{
ClassA a_classA;
a_classA.read()
mygeneralclass.set_data_classA(a_classA.data);
};


set_data_classA receives data By pointer (a_classA.data is a pointer);

Mygeneralclass is declared as private on the form I'm working.
I don't know how is it possible that I the data passed by pointer does not dissapear when the control of the program leaves the code for button_click.
Then data was created for a_classA, but the life of a_classA is restrited to the button_click, ins't it ?

set_data_classA is declared as set_data_classA(*data) {my_data=data]



It would not have to be an error ?
Thanks.
Last edited on
It's undefined behavior. You can't rely on the fact that the pointer is still pointing to a valid class. I would've expected, possibly, a segfault for that.
Topic archived. No new replies allowed.