e05-02.cpp

来自「游戏开发数据结构Data Structures for Game Program」· C++ 代码 · 共 49 行

CPP
49
字号
// =======================================================
//  Chapter 5, Example 2
//  Demonstrating the Array2D Class
// =======================================================
#include "Array2D.h"



void main()
{
    // declare the arrays.
    Array2D<int> iarray( 5, 5 );
    Array2D<float> farray( 4, 4 );

    int i, x, y;
    float f;

    // We cannot do this with the Array2D class:
    // iarray[4][4] = 10
    // do this instead:
    iarray.Get( 4, 4 ) = 10;
    
    // set a cell in farray.
    farray.Get( 3, 2 ) = 0.5f;
    
    // retrieve the cells that we just set.
    i = iarray.Get( 4, 4 );
    f = farray.Get( 3, 2 );

    // get the size of each array.
    i = iarray.Size();
    i = farray.Size();

    // fill the integer array with consecutive numbers
    for( y = 0; y < 5; y++ )
    {
        for( x = 0; x < 5; x++ )
        {
            iarray.Get( x, y ) = y * 5 + x;
        }
    }

    // resize the array to make it larger:
    iarray.Resize( 6, 6 );

    // resize the array to make is smaller:
    iarray.Resize( 3, 3 );

}

⌨️ 快捷键说明

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