无法使这些 C 风格的转换现代化
Unable to modernize these C-style casts
代码:
int CChristianLifeMinistryEditorDlg::CompareDate(const void* pArg1, const void* pArg2)
{
const STUDENT_ASSIGN_HIST_S* psAssign1 = *((STUDENT_ASSIGN_HIST_S * *)pArg1);
const STUDENT_ASSIGN_HIST_S* psAssign2 = *((STUDENT_ASSIGN_HIST_S * *)pArg2);
int iGreater = 0; // assume they are the same
if (psAssign1->datMeeting < psAssign2->datMeeting)
iGreater = -1;
else if (psAssign1->datMeeting > psAssign2->datMeeting)
iGreater = 1;
return iGreater;
}
我正在努力研究如何使 C 风格的转换现代化:
const STUDENT_ASSIGN_HIST_S* psAssign1 = *((STUDENT_ASSIGN_HIST_S * *)pArg1);
const STUDENT_ASSIGN_HIST_S* psAssign2 = *((STUDENT_ASSIGN_HIST_S * *)pArg2);
我试过了:
const STUDENT_ASSIGN_HIST_S* psAssign1 = *(static_cast<STUDENT_ASSIGN_HIST_S * *>(pArg1));
const STUDENT_ASSIGN_HIST_S* psAssign1 = *(reinterpret_cast<STUDENT_ASSIGN_HIST_S * *>(pArg1));
这两个实例 VS 都告诉我这是一个无效的转换。
你可以试试这个:
typedef const STUDENT_ASSIGN_HIST_S* PCSAHS;
//...
PCSAHS psAssign1 = *(static_cast<const PCSAHS*>(pArg1));
pArg1
有 const
限定符,因此在转换时需要保留它。
代码:
int CChristianLifeMinistryEditorDlg::CompareDate(const void* pArg1, const void* pArg2)
{
const STUDENT_ASSIGN_HIST_S* psAssign1 = *((STUDENT_ASSIGN_HIST_S * *)pArg1);
const STUDENT_ASSIGN_HIST_S* psAssign2 = *((STUDENT_ASSIGN_HIST_S * *)pArg2);
int iGreater = 0; // assume they are the same
if (psAssign1->datMeeting < psAssign2->datMeeting)
iGreater = -1;
else if (psAssign1->datMeeting > psAssign2->datMeeting)
iGreater = 1;
return iGreater;
}
我正在努力研究如何使 C 风格的转换现代化:
const STUDENT_ASSIGN_HIST_S* psAssign1 = *((STUDENT_ASSIGN_HIST_S * *)pArg1);
const STUDENT_ASSIGN_HIST_S* psAssign2 = *((STUDENT_ASSIGN_HIST_S * *)pArg2);
我试过了:
const STUDENT_ASSIGN_HIST_S* psAssign1 = *(static_cast<STUDENT_ASSIGN_HIST_S * *>(pArg1));
const STUDENT_ASSIGN_HIST_S* psAssign1 = *(reinterpret_cast<STUDENT_ASSIGN_HIST_S * *>(pArg1));
这两个实例 VS 都告诉我这是一个无效的转换。
你可以试试这个:
typedef const STUDENT_ASSIGN_HIST_S* PCSAHS;
//...
PCSAHS psAssign1 = *(static_cast<const PCSAHS*>(pArg1));
pArg1
有 const
限定符,因此在转换时需要保留它。