CheckPointer
CheckPointer
The function returns the type of the object pointer.
ENUM_POINTER_TYPE CheckPointer(
object* anyobject // object pointer
);Parameters
- anyobject
[in] Object pointer.
Return value
Returns a value from the ENUM_POINTER_TYPE enumeration.
Note
An attempt to call an incorrect pointer results in the critical termination of a program. That’s why it’s necessary to call the CheckPointer function before using a pointer. A pointer can be incorrect in the following cases:
This function can be used for checking pointer validity. A non-zero value warranties that the pointer can be used for accessing.
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
Object Pointers, Checking the Object Pointer, Object Delete Operator delete
Last updated on