And I need to free memory, taken by this variable.
If I use delete chText;
or delete[] chText;
Visual Studio reports, that "HEAP DESTRUCTION DETECTED".
But I need to free this memory, as it is a class' member, and I think that it can cause a memory leak when object will be destroyed. Or it will not cause leak?
char* chText = "Hello!"; is invalid current C++ (accepted as deprecated by older revisions of the C++ standard). The proper form is constchar* chText = "Hello!";
You do not (and in fact cannot) free the memory occupied by the string literal "Hello!". A string literal is a static object. Static objects are allocated at program startup and deallocated at termination.
As a guideline, you can only delete what you havenew'd.