, :
static_cast<CObject*>(pMine)
, "CMyObject" "CObject"; ;
static_cast<CMyObject*>(pObject)
, "CMyObject" "CObject";
static_cast<CObject**>(&pMine)
FAIL, "CMyObject *" "CObject *";
reinterpret_cast<CObject**>(&pMine)
- "reinterpret_cast"; ?
:
void CMapStringToOb::GetNextAssoc(
POSITION& rNextPosition,
CString& rKey,
CObject** ppValue)
{
*ppValue = (the pointer at the current position, point to an instance of "CMyObject");
}
, :
GetNextAssoc(pos, s, reinterpret_cast<CObject**>(&pMine))
, "pMine" "CMyObject" ;
, .
, - (: CYourObject CMyObject)
myMap.SetAt(_T("a"), new CYourObject(_T("aaa")));
GetNextAssoc(pos, s, reinterpret_cast<CObject**>(&pMine));
Compilation time will still be executed, however pMine now points to "CYourObject", which will be UNDEFINED BEHAVIOR at runtime . (static_cast has the same problem though)
source
share