CObArray::GetData
Use this member function to gain direct access to the elements in the array.
const CObject** GetData( ) const;
CObject** GetData( );
Return Value
A pointer to the array of CObject pointers.
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.
The following table shows other member functions that are similar to CObArray::GetData.
Class |
Member Function |
---|---|
const BYTE* GetData( ) const;BYTE* GetData( ); |
|
const DWORD* GetData( ) const;DWORD* GetData( ); |
|
const void** GetData( ) const;void** GetData( ); |
|
const CString* GetData( ) const;CString* GetData( ); |
|
const UINT* GetData( ) const;UINT* GetData( ); |
|
const WORD* GetData( ) const;WORD* GetData( ); |
Example
See CObList::CObList for a listing of the CAge class used in all collection examples.
CObArray myArray;
// Allocate memory for at least 32 elements.
myArray.SetSize(32, 128);
// Add elements to the array.
CAge** ppAge = (CAge**) myArray.GetData();
for (int i = 0; i < 32; i++, ppAge++)
*ppAge = new CAge(i);
// Only keep first 5 elements and free extra (unused) bytes.
for (int i = 5; i < myArray.GetCount(); i++)
{
delete myArray[i]; // free objects before resetting array size.
}
myArray.SetSize(5, 128);
myArray.FreeExtra(); // only frees pointers.
#ifdef _DEBUG
afxDump.SetDepth(1);
afxDump << _T("myArray: ") << &myArray << _T("\n");
#endif
Requirements
Header: afxcoll.h