arindam042099
asked on
dynamic allocation for multidimensional array Ymatrix
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];
}
rect **Ymatrix
Ymatrix = new (rect*)[6];
for(j=0; j<6; j++)
{
Ymatrix[j] = new rect[6];
}
I would seriously consider using the STL vector class and avoid the whole thing.
ASKER
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
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
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?
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?
ASKER
Glenn I am sorry I rejected the answer .. It works ...Thanks
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.
ASKER
It was not there in his comment box .. But was in your comment box
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks, I'll report it.
Hi,
instead U try this one
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
instead U try this one
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
Instead, go
typedef rect * prect;
Ymatrix = new prect[6];
for (j=0;j<6;j++)
{
Ymatrix[j]=new rect[6];
}
Glenn