Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dynamically sized multidimensional arrays

Posted on 1997-09-04
3
Medium Priority
?
251 Views
Last Modified: 2009-12-16
I'd like to know how to initialise multidimensional arrays using CArray in VC++.
The solutions I've come up with look quite messy and not very elegant.
0
Comment
Question by:Reil
3 Comments
 
LVL 4

Expert Comment

by:md041797
ID: 1168777
They are automatically initialized.  What are you asking?
0
 

Author Comment

by:Reil
ID: 1168778
Md, you're probably talking about one-dimensional dynamic arrays. They are not a problem, using CArray. But as soon as you need another dimension it becomes tricky, I think.
0
 
LVL 1

Accepted Solution

by:
ohell earned 200 total points
ID: 1168779
The output of the following code shows that just creating the arrays and allocating memory is enough to initialise the array.
Hope this is of help.

struct myInt{
      int i;
      myInt() { i = 5; }
};

void SomeFunc()
{
      typedef CArray<myInt, myInt&> intArray;

      CArray<intArray, intArray&> array;

      array.SetSize(5);
      for (int i = 0; i < 5; i++) {
            array[i].SetSize(5);
            for (int j = 0; j < 5; j++)
            printf("%d\n", array[i][j].i);
      }
}

Output:
5
5
5
5
5
5
5
5
5
5
5
5
5
5
...

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question