CheckPointer Function
Overview
The CheckPointer function returns the type of an object pointer. It is crucial for validating pointer integrity before accessing the object to prevent critical program termination.
Signature
ENUM_POINTER_TYPE CheckPointer(object* anyobject);
Parameters
anyobject [in]: A pointer to an object.Return Value
Returns a value from the ENUM_POINTER_TYPE enumeration, indicating the pointer's validity.
Notes
NULL or a pointer to a deleted object) will cause critical program termination if not checked.CheckPointer before using a pointer is recommended.Related Functions
AlertCommentGetPointerMessageBoxPrintResetLastErrorSetUserErrorSleepZeroMemoryConstants
ENUM_POINTER_TYPE (for return values)Example
//+------------------------------------------------------------------+
//| Deletes list by deleting its elements |
//+------------------------------------------------------------------+
void CMyList::Destroy()
{
//--- service pointer for working in the loop
CItem* item;
//--- go through loop and try to delete dynamic pointers
while(CheckPointer(m_items)!=POINTER_INVALID)
{
item=m_items;
m_items=m_items.Next();
if(CheckPointer(item)==POINTER_DYNAMIC)
{
Print("Dynamyc object ",item.Identifier()," to be deleted");
delete (item);
}
else Print("Non-dynamic object ",item.Identifier()," cannot be deleted");
}
//---
}
See Also
Previous
arrow_back
Alert