繁体   English   中英

C ++ std :: list插入问题

[英]C++ std::list problems with insert

在过去的几天里,我在这里待了几个小时,并且在网上尽可能地搜索有关此问题的答案,因此我陷入了困境。 当我认为MSDN对我有答案时,我仍然遇到问题。 我有一个带有class InstalledProgram{}的头文件InstalledPrograms.h

三个构造函数

#ifdef CONSTRUCTOR
    InstalledProgram::InstalledProgram();
    InstalledProgram::InstalledProgram(String^ p_DisplayName);
    InstalledProgram::InstalledProgram(String^ p_DisplayName, String^ p_ParentDisplayName, string p_Version);
#endif

我声明列表: list<InstalledProgram> ProgramList;

将其传递给此函数:

list<InstalledProgram> InstalledProgram::GetUserUninstallKeyPrograms(RegistryKey ^CurUserInstallKey, RegistryKey^ HkeylmRoot, list<InstalledProgram> paramProgramList)

像这样

GetUserUninstallKeyPrograms(Wow64UninstallKey, ClassKey, ProgramList);

做一些事情,然后我在代码中指出了将新实例插入列表的必要步骤:

paramProgramList.insert(paramProgramList.end(), new InstalledProgram(Name));

我遇到的问题是“。” 在插入之前显示“没有重载函数的实例与参数列表匹配”,而InstalledProgram(Name)的括号中显示“没有参数类型(System :: String ^)的构造函数实例”。

我不明白为什么。

任何帮助,将不胜感激。

paramProgramList是一个list<InstalledProgram>但是您尝试插入new InstalledProgram(Name) ,它是指向 InstalledProgram指针 如果InstalledProgram是可复制的,则只需删除单词new

至于“没有构造函数实例的参数类型(System :: String ^)”; 除非未定义CONSTRUCTOR,否则无法从我看到的代码中进行解释。

另外,虽然按照您的方式编写插入在技术上没有任何错误,但这会更加简洁:

paramProgramList.push_back(InstalledProgram(Name));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM