Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to delete/free const char*?

I have a std::vector<const char*> which I populate by .push_back("something"). How to delete contents not including std::string‘s header? delete segfaults, and std::free needs void* and it "cannot initialize [..] with an lvalue of type ‘const char *’".

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

String literals have static storage duration. You may not delete them using the operator delete. String literals will be alive until the program ends,

You may delete what was created using the operator new.

You can just erase all or selected elements of the vector or clear it entirely.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading