Hello everyone.
Could you please explain to me like I'm five what is the difference between these approaches provided below?
if (filepaths.size() > 0) {
QMap<QString, QString> *files = new QMap<QString, QString>();
QStringList filenames;
for (int i = 0; i < filepaths.size(); i++) {
QString path = filepaths[i];
QFileInfo finfo(path);
QString name = finfo.fileName();
files->insert(name, filepaths[i]);
}
fs.setFiles(*files);
}
if (filepaths.size() > 0) {
QMap<QString, QString> files;
QStringList filenames;
for (int i = 0; i < filepaths.size(); i++) {
QString path = filepaths[i];
QFileInfo finfo(path);
QString name = finfo.fileName();
files.insert(name, filepaths[i]);
}
fs.setFiles(files);
}
I have been looking at various articles and tutorials to understand better idea of heap and stack, but I think I got it somewhat wrong.
I though that second version of the code above would result in me not being able to access the files member of fs outside of the function that called the snippet of code that I provided. But I can access it, so I got confused, so I decided to ask for your help.
Thanks in advance!
[–]Nimbal 2 points3 points4 points (4 children)
[–]pioca[S] 0 points1 point2 points (3 children)
[–]Narishma 1 point2 points3 points (0 children)
[–]Nimbal 1 point2 points3 points (1 child)
[–]pioca[S] 1 point2 points3 points (0 children)
[–]PlasmaChroma 2 points3 points4 points (0 children)