⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e05-02.cpp

📁 游戏开发数据结构Data Structures for Game Programmers
💻 CPP
字号:
// =======================================================
//  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -