Partager via


CArray::GetData

Use this member function to gain direct access to the elements in an array.

const TYPE* GetData( ) const;
TYPE* GetData( );

Parameters

  • TYPE
    Template parameter specifying the type of the array elements.

Return Value

A pointer to an array element.

Remarks

If no elements are available, GetData returns a null value.

While direct access to the elements of an array can help you work more quickly, use caution when calling GetData; any errors you make directly affect the elements of your array.

Example

CArray<CPoint,CPoint> myArray;

// Allocate memory for at least 32 elements.
myArray.SetSize(32, 128);

// Add elements to the array.
CPoint* pPt = (CPoint*) myArray.GetData();
for (int i = 0; i < 32; i++, pPt++)
   *pPt = CPoint(i, 2*i);

// Only keep first 5 elements and free extra (unused) bytes.
myArray.SetSize(5, 128);
myArray.FreeExtra();

#if _DEBUG
   afxDump.SetDepth(1);
   afxDump << "myArray: " << &myArray << "\n";
#endif

Requirements

Header: afxtempl.h

See Also

Concepts

CArray Class

CArray Members

Hierarchy Chart

CArray::GetAt

CArray::SetAt

CArray::ElementAt