简体   繁体   English

C ++ std :: list插入问题

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

I have been at this for a few hours over the past couple of days and search as best as I could online for an answer to this and I am stuck. 在过去的几天里,我在这里待了几个小时,并且在网上尽可能地搜索有关此问题的答案,因此我陷入了困境。 Just when I think MSDN has an answer for me, I still get a problem. 当我认为MSDN对我有答案时,我仍然遇到问题。 I have a header InstalledPrograms.h with class InstalledProgram{} . 我有一个带有class InstalledProgram{}的头文件InstalledPrograms.h

Three Constructors 三个构造函数

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

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

Pass it to this function: 将其传递给此函数:

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

like this 像这样

GetUserUninstallKeyPrograms(Wow64UninstallKey, ClassKey, ProgramList);

Do some stuff and I get to a point in the code that I need to insert a new instance into the list: 做一些事情,然后我在代码中指出了将新实例插入列表的必要步骤:

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

The Problem I have having is that the "." 我遇到的问题是“。” before insert shows "No instance of overloaded function matches the argument list", and the Parentheses around InstalledProgram(Name) show "No instance of constructor for argument type (System::String ^)". 在插入之前显示“没有重载函数的实例与参数列表匹配”,而InstalledProgram(Name)的括号中显示“没有参数类型(System :: String ^)的构造函数实例”。

I don't understand why. 我不明白为什么。

Any help would be appreciated. 任何帮助,将不胜感激。

paramProgramList is a list<InstalledProgram> but you are trying to insert new InstalledProgram(Name) which is a pointer to an InstalledProgram . paramProgramList是一个list<InstalledProgram>但是您尝试插入new InstalledProgram(Name) ,它是指向 InstalledProgram指针 If InstalledProgram is copyable, you can just remove the word new . 如果InstalledProgram是可复制的,则只需删除单词new

As for "No instance of constructor for argument type (System::String ^)"; 至于“没有构造函数实例的参数类型(System :: String ^)”; that I can't explain from the code I see unless CONSTRUCTOR is not defined. 除非未定义CONSTRUCTOR,否则无法从我看到的代码中进行解释。

Also, while there's nothing technically wrong with writing the insertion the way you did, this would be a bit more succinct: 另外,虽然按照您的方式编写插入在技术上没有任何错误,但这会更加简洁:

paramProgramList.push_back(InstalledProgram(Name));

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

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