2.2.7.1.2 Array::Array

Description

Default constructor to create an empty array

Syntax

Array( BOOL bOwner = FALSE )

Parameters

bOwner
[input] If set as true, all the items in it will be destroyed when the array destroy

Return

Examples

EX1

#include <Array.h>
struct PERSON
{
	int nID;
};
void Array_Array_ex1()
{
	Array<PERSON&> arp(true); //set as owner, will destroy all the items in it when get out of this function, though some items may be created in heap
	PERSON *p = new PERSON;
	p->nID = 555;
	arp.Add(*p); //add local variable
	for ( int ii = 0; ii < 4; ii++ )
	{
		PERSON* tp = new PERSON; //add variable created in heap
		tp->nID = ii + 1;
		arp.Add(*tp);
	}
 
	PERSON& rp = arp.GetAt(0);
	rp.nID = 258; //note, change rp's value will change p's value since rp and p refer to the same object
	printf("Person p's ID is : %d\n", p->nID);
	for ( ii = 0; ii < arp.GetSize(); ii++ )
	{
		printf("Person %d's ID is : %d\n", ii+1, arp.GetAt(ii).nID);
	}
}

Remark

See Also

Array::IsOwner

Header to Include

Array.h