假设我有以下代码(C++/Qt):
QHash<QString, AppInfo*> links;
QList<AppInfo> apps = m_apps.values();
for (const AppInfo &app : apps) {
// Doing something with #app variable...
links.insert(app.other._appFile, &app);
}
m_apps
is QHash<QString, AppInfo>
,并且app.other._appFile
是文件的完整路径。
&app
问题来了:倒数第二行的构造是否正确?我需要一个指向 AppInfo 对象的非常量指针,以便稍后对其进行修改。是否直接&app
链接到const AppInfo&
或AppInfo
对象?如果我尝试修改获得的AppInfo*
对象,应用程序不会崩溃吗?谢谢你。
抱歉,英语不是我的母语,我无法完美地制定问题标题。请代替我做。