0
what's wrong in my code
why typeid is not working in my code as below: https://code.sololearn.com/cA2A23A12a16
2 Réponses
+ 4
The if-condition on line 43 is true and hence line 45 gets executed. On line 45, `pd` is assigned `pbd` casted to D*. Here a new object of type D is NOT constructed. Therefore, now `pd` literally points to what `pbd` points to.
Now on line 57, you deallocate `pbd` and then on line 58, you deallocate `pd`. As `pd` points to the same location as `pbd`, you are trying to free memory that has already been freed when line 57 was executed. This results in the segmentation fault. Simply remove line 58 as it is not needed because the memory it points to has already been freed.
+ 1
I tried on codechef online ide your code showing SIGSEGV is an error(signal) caused by an invalid memory reference or a segmentation fault. you trying to use too much memory.