现在的位置: 首页 > 综合 > 正文

ACE 容器之一 ACE_Array 的使用

2019年01月10日 ⁄ 综合 ⁄ 共 728字 ⁄ 字号 评论关闭

ACE_Array增加越界访问控制,以下为测试代码。

// sctpserver.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "ace/Containers.h"

int _tmain(int argc, _TCHAR* argv[])
{

	ACE_Array<int> arr(10);

	//set value
	for(int index=0; index<10; index++)
	{
		//the first parameter is value, and the second paramter is index
		int value = index * 10;
		arr.set(value, index);
	}

	//get value
	for(int index=0; index<10; index++)
	{
		int value = 0;
		arr.get(value, index);
		printf("%d\n", value);
	}

	int value = 0;
	int index = 100;
	printf("illegal get value = %d\n", arr.get(value, index));

	//get size of array
	printf("size=%d\n", arr.size());

	//整体赋值操作
	ACE_Array<int> copy;
	copy = arr;


	//使用跌代器访问
	ACE_Array<int>::ITERATOR iter(copy);
	while (!iter.done ())
    {
      int* data;
      iter.next(data);
      printf("%d\n",*data);
      iter.advance ();
    }

	getchar();
	return 0;
}

 

抱歉!评论已关闭.