Solved

# dynamic allocation for multidimensional array Ymatrix

Posted on 2000-01-19
Medium Priority
241 Views
I have a class rect to define complex numbers...I am trying to define a multidimentional array Ymatrix using the new operator ,,.. It is giving me a error in the second line ... Can anyone tell me why and how to rectify it ...

rect  **Ymatrix
Ymatrix = new (rect*)[6];
for(j=0; j<6; j++)
{
Ymatrix[j] = new rect[6];
}
0
Question by:arindam042099
• 4
• 3
• 2
• +1

LVL 3

Expert Comment

ID: 2368072
arindam:

typedef rect * prect;
Ymatrix = new prect[6];
for (j=0;j<6;j++)
{
Ymatrix[j]=new rect[6];
}

Glenn
0

LVL 22

Expert Comment

ID: 2368092
I would seriously consider using the STL vector class and avoid the whole thing.
0

Author Comment

ID: 2368146
glenn the method you showed me gives errors as well ..
Nietod, I know you had asked me to use STL, but right now I do not have the book that talks about that or have a example to see how I could possibly do the above using me...Being new to C++ is a major disadvantage because sending question in these kinds of places people assume that I know what they are referring at the tip of my thumb .. so I have temporarily resorted to using the new operator ...

arindam
0

LVL 22

Expert Comment

ID: 2368253
Learning C++ is very tough, but also very worthwhile.  I think you will find that learning to use the sTL vector class will end up saving you a lot of time in effort.

Although I think a good book, like the stroustrup book is much better, you can find a lot about the STL at

http://www.sgi.com/Technology/STL/index.html

In you original code, I see two problems, you don't have a sem-colon at the end of the first line (" rect  **Ymatrix")  And you have those parenthesis in the 1st new [] allocation.  Remove the parenthesis and add that semi-colon and you should be fine.

However this code also requires that the rect class have a default constructor.  Does it?
0

Author Comment

ID: 2368264
Glenn I am sorry I rejected the answer .. It works ...Thanks
0

LVL 22

Expert Comment

ID: 2368343
arindam, there is an oprtion to accept a comment as an answer.  It appears as a link at the top of a comment box.  However, I don't know if it appears at the top of a rejected answer box (it should, but didn't earlier).  If it is there, you can re-accept the Glenn's anwser.  If not, would you post a note letting me know.  I'll pass it onto the EE programmers.  There is a new version to be released on Monday and I'd like to see it fixed in that one.
0

Author Comment

ID: 2368676
It was not there in his comment box .. But was in your comment box
0

LVL 3

Accepted Solution

GlennDean earned 20 total points
ID: 2368946
Thanxs arindam
0

LVL 22

Expert Comment

ID: 2369220
Thanks, I'll report it.
0

Expert Comment

ID: 2384591
Hi,
CRect  **m_pYmatrix2; // 2-d ptr
// Number of rows
*m_pYmatrix2 = new CRect[Row];

for(j=0; j<Row; j++)
{
*m_pYmatrix2[j] = new CRect[Col];
}

Hope this will help
Sisu
0

## Featured Post

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
###### Suggested Courses
Course of the Month3 days, 17 hours left to enroll