+ Reply to Thread
Results 1 to 3 of 3

Thread: STL question

  1. #1
    Join Date
    May 2005
    Posts
    390

    Default STL question

    Is there something that looks like a 2-dimensional array?

  2. #2
    Join Date
    Mar 2005
    Location
    California
    Posts
    2,097

    Default

    Not specifically, but most of them can be nested.

    vector <vector <int>> SomeInt;

    SomeInt.resize(100);
    SomeInt[20].push_back(7);

    printf("%i", SomeInt[20][0]);

    will print 7

    SomeInt[30].resize(20);

    SomeInt[30][15] = 12;

    and so on.
    "They laughed when I said I was going to be a comedian ... They're not laughing now." - Bob Monkhouse

  3. #3
    Join Date
    May 2005
    Posts
    390

    Default

    Turns out the CLR provides a template array definition that allows n-dimensional (not jagged) arrays:

    array<int^, 2>
    creates a 2-d array of int.

    Code:
    array<int^, 2> n = gcnew array<int^, 2> (3, 4);
    I have a class that has such an array in it, and a 2-arg constructor. The ctor allocates the array as follows:
    Code:
    Hexes = gcnew array<Hex^, 2>( _x, _y );
    One of the weird things (to me) about Java and .Net languages is that creating an array doesn't create the underlying objects. Map^m = gcnew Map(2, 3) creates a 6-element 2-d array. I have an output statement in the Hex ctor that does not get called.

+ Reply to Thread

Similar Threads

  1. The question from a new user
    By GRIENlord in forum General Chit Chat
    Replies: 6
    Last Post: 04-17-2007, 03:49 AM
  2. DDO Char Gen Question
    By Seipherwood in forum Character Planner
    Replies: 6
    Last Post: 11-30-2006, 01:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts