I am trying to create a constructor that deletes a directory objects name, then the subdirectories within the directory, and finally the directory itself. The delete [] *subDirectories line however causes segfaults whenever used.
Subdirectories are allocated by
subDirectories[subDirectoryCount++] = new Directory(arguments[1], umask, time, this);
Directory::~Directory()
{
delete [] name;
for (int i = 0; i < subDirectoryCount; i++)
delete subDirectories[i];
delete [] *subDirectories;
}
delete [] subDirectories. Make suresubDirectorieswas created withnew[], otherwise you have undefined behavior.std::vector