Вопрос

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. I have a header InstalledPrograms.h with class InstalledProgram{}.

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;

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 ^)".

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. If InstalledProgram is copyable, you can just remove the word new.

As for "No instance of constructor for argument type (System::String ^)"; that I can't explain from the code I see unless CONSTRUCTOR is not defined.

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 с атрибуция
Не связан с StackOverflow
scroll top