Insert

在列表中按指定位置插入元素。

int  Insert(

   CObject*  element,     // 插入的元素

   int       pos          // 位置

   )

参数

element

[输入]  插入到列表中的元素值。

pos

[输入]  插入到列表的位置。

返回值

如果成功, 返回插入元素的索引, 或在出错时 -1。

注释

如果传递无效指针值 (比如 NULL), 则元素不会被加入列表。

例如:

//--- 例程 CList::Insert(CObject*,int)

#include <Arrays\List.mqh>

//--- 

void OnStart()

  {

   CList *list=new CList;

   //--- 

   if(list==NULL)

     {

      printf("对象创建错误");

      return;

     }

   //--- 插入 100 个元素 

   for(int i=0;i<100;i++)

     {

      if(list.Insert(new CObject,0)==-1)

        {

         printf("元素插入错误");

         delete list;

         return;

        }

     }

   //--- 使用列表 

   //--- . . . 

   //--- 删除列表 

   delete list;

  }