簡體   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