e03-03.cpp

来自「游戏开发数据结构-Data.Structures.for.Game.Progra」· C++ 代码 · 共 42 行

CPP
42
字号
// =======================================================
//  Chapter 3, Example 3
//  The Array Class
// =======================================================
#include "Array.h"



void main()
{
    // create two arrays, one for an integer array
    // and one for a float array.
    Array<int> intarray( 10 );
    Array<float> floatarray( 5 );

    // use the access operator to store values.
    intarray[0] = 10;
    floatarray[0] = 3.1415f;

    // use the access operator to retrieve values.
    int i = intarray[0];
    float f = floatarray[0];
    
    // store values at index 1 in both arrays.
    intarray[1] = 12;
    floatarray[1] = 6.28f;

    // insert values between cells 0 and 1 in both arrays.
    intarray.Insert( 11, 1 );
    floatarray.Insert( 4.2f, 1 );

    // remove the items at cell 0 in both arrays.
    intarray.Remove( 0 );
    floatarray.Remove( 0 );

    // resize both arrays
    intarray.Resize( 3 );
    floatarray.Resize( 4 );

    // both arrays are automatically deleted by the Array
    // class destructor.
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?