다음을 통해 공유


CObArray::InsertAt

요소를 다른 배열의 모든 요소는 지정 된 인덱스에 삽입합니다.

void InsertAt(
   INT_PTR nIndex,
   CObject* newElement,
   INT_PTR nCount = 1 
);
void InsertAt(
   INT_PTR nStartIndex,
   CObArray* pNewArray 
);

매개 변수

  • nIndex
    반환 된 값 보다 클 수는 정수 인덱스 GetUpperBound.

  • newElement
    CObject 포인터를이 배열에 배치 합니다.A newElement 값의 NULL 사용할 수 있습니다.

  • nCount
    이 요소가 수 해야 하는 횟수 (기본값은 1) 삽입 합니다.

  • nStartIndex
    반환 된 값 보다 클 수는 정수 인덱스 GetUpperBound.

  • pNewArray
    이 배열에 추가할 요소를 포함 하는 다른 배열입니다.

설명

첫 번째 버전의 InsertAt 요소 (또는 요소 여러 복사본) 배열의 지정 된 인덱스에 삽입 합니다.이 과정에서 이동이 인덱스에 기존 요소 이동 (인덱스 증가) 위의 모든 요소를.

두 번째 버전에서 다른 모든 요소를 삽입 CObArray 부터 컬렉션의 nStartIndex 위치.

SetAt 반대로 함수 지정 된 배열의 요소를 대체 하 고 모든 요소를 이동 하지.

다음 표에서 다른 멤버와 비슷한 함수를 보여 줍니다. CObArray::InsertAt.

클래스

멤버 함수

CByteArray

void InsertAt( INT_PTR nIndex, BYTE newElement, int nCount=1 );

    (CMemoryException *)를 throw 합니다.

void InsertAt( INT_PTR nStartIndex, CByteArray* pNewArray );

    (CMemoryException *)를 throw 합니다.

CDWordArray

void InsertAt( INT_PTR nIndex, DWORD newElement, int nCount=1 );

    (CMemoryException *)를 throw 합니다.

void InsertAt( INT_PTR nStartIndex, CDWordArray* pNewArray );

    (CMemoryException *)를 throw 합니다.

해당 클래스가

void InsertAt( INT_PTR nIndex, void* newElement, int nCount=1 );

    (CMemoryException *)를 throw 합니다.

void InsertAt( INT_PTR nStartIndex, CPtrArray* pNewArray );

    (CMemoryException *)를 throw 합니다.

CStringArray

void InsertAt( INT_PTR nIndex, LPCTSTR newElement, int nCount=1 );

    (CMemoryException *)를 throw 합니다.

void InsertAt( INT_PTR nStartIndex, CStringArray* pNewArray );

    (CMemoryException *)를 throw 합니다.

CUIntArray

void InsertAt( INT_PTR nIndex, UINT newElement, int nCount=1 );

    (CMemoryException *)를 throw 합니다.

void InsertAt( INT_PTR nStartIndex, CUIntArray* pNewArray );

    (CMemoryException *)를 throw 합니다.

CWordArray

void InsertAt( INT_PTR nIndex, WORD newElement, int nCount=1 );

    (CMemoryException *)를 throw 합니다.

void InsertAt( INT_PTR nStartIndex, CWordArray* pNewArray );

    (CMemoryException *)를 throw 합니다.

예제

참조 하십시오 CObList::CObList 에 CAge 모든 컬렉션 예제에 사용 되는 클래스입니다.

CObArray arr;

arr.Add(new CAge(21)); // Element 0
arr.Add(new CAge(40)); // Element 1 (will become 2).
arr.InsertAt(1, new CAge(30));  // New element 1
#ifdef _DEBUG
   afxDump.SetDepth(1);
   afxDump << _T("InsertAt example: ") << &arr << _T("\n");
#endif      

이 프로그램의 결과 다음과 같습니다.

InsertAt example: A CObArray with 3 elements

[0] = a CAge at $45C8 21

[1] = a CAge at $4646 30

[2] = a CAge at $4606 40

요구 사항

헤더: afxcoll.h

참고 항목

참조

CObArray 클래스

계층 구조 차트

CObArray::SetAt

CObArray::RemoveAt