I am trying to write this function:
void CChristianLifeMinistryEditorDlg::PerformAutoAssignForAssignment(
const MSAToolsLibrary::AssignmentType eAssignType,
const CString strStartingName,
std::function<void(CString)> funcSetAssignName)
{
CString strName = L"abc";
CChristianLifeMinistryEntry *pEntry = xxx;
// ...
pEntry->funcSetAssignName(strName);
}
I am having difficulty in passing a function to it:
PerformAutoAssignForAssignment(MSAToolsLibrary::AssignmentType_Host, L"Name 1" );
PerformAutoAssignForAssignment(MSAToolsLibrary::AssignmentType_CoHost, L"Name 2");
PerformAutoAssignForAssignment(MSAToolsLibrary::AssignmentType_ConductorCBS, L"Name 3");
PerformAutoAssignForAssignment(MSAToolsLibrary::AssignmentType_ReaderCBS, L"Name 4");
At the moment I am not passing a function:
void CChristianLifeMinistryEditorDlg::PerformAutoAssignForAssignment(
const MSAToolsLibrary::AssignmentType eAssignType,
const CString strStartingName)
{
CString strName = L"abc";
CChristianLifeMinistryEntry *pEntry = xxx;
// ...
pEntry->funcSetAssignName(strName);
if (eAssignType == MSAToolsLibrary::AssignmentType_ConductorCBS)
{
pEntry->SetCBSConductor(strNameToUse);
}
else if (eAssignType == MSAToolsLibrary::AssignmentType_ReaderCBS)
{
pEntry->SetCBSReader(strNameToUse);
}
else if (eAssignType == MSAToolsLibrary::AssignmentType_Host)
{
pEntry->SetVideoHost(strNameToUse);
}
else if (eAssignType == MSAToolsLibrary::AssignmentType_CoHost)
{
pEntry->SetVideoCohost(strNameToUse);
}
}
Can you see what I am trying to do? I had hoped to avoid the if/else
ladder because eventually I will have more functions to add to the ladder for other assignments. I had hoped I could pass them as a function.