ddArray
Adiciona ao final dos elementos array a partir de um outro array.
bool AddArray(
const CArrayObj * src array-
)
|
Parâmetros
src
[in] Ponteiro para uma instância de classe CArrayDouble - fontes de elementos para adicionar.
Valor do Retorno
Observação
//--- example
extern bool make_error;
extern int error;
extern CArrayObj *src;
//--- Create a new instance CArrayObj
//--- Default memory management is turned on
CArrayObj *array=new CArrayObj;
//--- Add (copy) the elements of the source array
if(array!=NULL)
bool result=array.AddArray(src);
if(make_error)
{
//--- Perform erroneous actions
switch(error)
{
case 0:
//--- Remove the source array, without checking its memory management flag
delete src;
//--- Result:
//--- It is possible to address an element by invalid pointer in the receiver array
break;
case 1:
//--- Disable the mechanism of memory management in the source array
if(src.FreeMode()) src.FreeMode(false);
//--- But do not remove the source array
//--- Result:
//--- After removing the receiver array it is possible to address an element by invalid pointer in the source array
break;
case 2:
//--- Disable the mechanism of memory management in the source array
src.FreeMode(false);
//--- Disable the mechanism of memory management in the receiver array
array.FreeMode(false);
//--- Result:
//--- After the program termination get a "memory leak"
break;
}
}
else
{
//--- Disable the mechanism of memory management in the source array
if(src.FreeMode()) src.FreeMode(false);
//--- Delete the source array
delete src;
//--- Result:
//--- Addressing the receiver array element will be correct
//--- Deleting the receiver array will lead to deleting its elements
}
|
Exemplo
//--- example for CArrayObj::AddArray(const CArrayObj*)
#include <Arrays\ArrayObj.mqh>
//---
void OnStart()
{
CArrayObj *array=new CArrayObj;
//---
if(array==NULL)
{
printf("Object create error");
return;
}
//--- create source array
CArrayObj *src=new CArrayObj;
if(src==NULL)
{
printf("Object create error");
delete array;
return;
}
//--- reset free mode flag
src.FreeMode(false);
//--- fill source array
//--- . . .
//--- add another array
if(!array.AddArray(src))
{
printf("Array addition error");
delete src;
delete array;
return;
}
//--- delete source array without elements
delete src;
//--- use array
//--- . . .
//--- delete array
delete array;
}
|