I know that pointers are a lot like arrays (if not one and the same) in a way, but I'm having trouble deciphering when I should explicitly delete a pointer.
Take this code for example:
#include <vector>
int main(int argc, char** argv)
{
std::vector<char*> strings;
strings.push_back(argv[0]);
return 0;
}
Now obviously, no one in their right mind would make a program exactly like this, but for pure discussion, let's say this is my program. Should I have deleted strings.at(0)
to avoid a memory leak there, or is the data considered a character array to be destroyed when the program terminates?
Similarly, suppose I have a vector
of a class I've created, and I've declared them all as new
instances of the class. Do I then need to delete, or is it fine?
I'm a self-taught programmer, so these complicated (and sometimes dangerous) concepts make me paranoid.