How to deal with a class destructor, including Union

I have a class containing type variables of this type.

class Field { union DATATYPE { int intValue; double doubleValue; char* charValue; MyClass* MyClassValue; } Value; ~Field() { delete[] Value.charValue; delete Value.MyClassValue; } } 

This destructor gives an error. Since some objects do not have an initialized charValue, an attempt to delete it caused an error.

+4
source share

All Articles