2014-04-25 61 views
0

在過去的幾天裏,我一直在這裏待了幾個小時,並且儘可能地搜索到了最好的結果,因爲我可以在線獲得對此的回答,並且我被卡住了。就在我認爲MSDN對我有答案時,我仍然遇到問題。我有一個標題InstalledPrograms.hclass InstalledProgram{}C++ std :: list插入問題

三個構造

#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)的圓括號顯示「No 參數類型(System :: String ^)」的構造函數的實例。

我不明白爲什麼。

任何幫助,將不勝感激。

回答

0

paramProgramList是list<InstalledProgram>但你要插入new InstalledProgram(Name)這是一個指針InstalledProgram。如果InstalledProgram是可複製的,則可以刪除單詞new

至於「沒有參數類型(System :: String ^)的構造函數實例」;我無法從我看到的代碼中解釋,除非CONSTRUCTOR未定義。

此外,雖然沒有什麼技術上的錯誤和寫入插入你的方式,這將是一個有點更簡潔:

paramProgramList.push_back(InstalledProgram(Name)); 
+0

我沒有一個拷貝構造函數。我不認爲我會用一個。但是我添加了一個,它仍然拒絕接受String ^的參數Name。我最終不得不創建一個空的新實例,手動設置該值,然後在將其傳遞給push_back之前進行復制。 –

+0

我不能確定沒有看到InstalledProgram的整個定義,但如果這是真的,我認爲這意味着CONSTRUCTOR沒有定義。 – dlf