So I have a union type struct that contains a pointer to a string as one of the types the union can hold and I want to overload the = operator so I can do assignments. In order to ensure that I do not have a memory leak I am checking to see if the type of the union is already a string, if it is I delete the old value and assign the new value.
My issue is that if i do "aString = aString" my check deletes the string that it means to assign and this causes a segfault of course. I know that this is not something that I would ever need to use but I just want to ensure that this case is handled properly. So my question is how can I handle this properly?