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];
      }
arindam042099Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GlennDeanCommented:
arindam:
  Instead, go

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

  Glenn
0
nietodCommented:
I would seriously consider using the STL vector class and avoid the whole thing.
0
arindam042099Author Commented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

nietodCommented:
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
arindam042099Author Commented:
Glenn I am sorry I rejected the answer .. It works ...Thanks
0
nietodCommented:
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
arindam042099Author Commented:
It was not there in his comment box .. But was in your comment box
0
GlennDeanCommented:
Thanxs arindam
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
Thanks, I'll report it.
0
sisuCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.