使用此成员函数获取直接访问数组中的元素。
const TYPE* GetData( ) const;
TYPE* GetData( );
参数
- 类型
指定数组元素的类型模板参数。
返回值
对数组元素的指针。
备注
如果元素不可用,GetData 返回空值。
当直接访问数组中的元素可帮助您快速工作,注意,在调用 GetData时;所有错误您直接进行影响元素您的数组。
示例
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
要求
Header: afxtempl.h