Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

Array of class and a pointer to it

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eitan - 04 May 2005 01:13 GMT
Hello,

I defined a class name MyClass.

I would like to define an array of 4 by 8 of that class.
I would like to define a pointer to the array of MyClass.

I tried it with static definition:
MyClass    m_MyClass[4][8] ;
I can not seem to find the way to define a pointer to this array?!?!?

I tried also to define it with the new operator but had similar results.

Any ideas how to do it?

Eitan
Boni - 04 May 2005 13:43 GMT
How about
MyClass ** ppMyClass;
ppMyClass=m_MyClass; or the same
ppMyClass=&m_MyClass[0][0];
or dynamically
MyClass ** ppMyClass=new  MyClass   *[4]
for (int i=0;i<8;++i){
   ppMyClass[i]=new  MyClass   [8]
}

Don't forget to do the same when you delete (not just delete[]ppMyClass)
Hope it helps,
Boni
> Hello,
>
[quoted text clipped - 12 lines]
>
> Eitan
Brian Muth - 04 May 2005 22:25 GMT
> How about
> MyClass ** ppMyClass;
> ppMyClass=m_MyClass; or the same

No, the above line is invalid.

> ppMyClass=&m_MyClass[0][0];

and this line is also invalid.

> or dynamically
> MyClass ** ppMyClass=new  MyClass   *[4]
> for (int i=0;i<8;++i){
>     ppMyClass[i]=new  MyClass   [8]
> }

Ah, but that's not the same, is it? You have created an array of pointers,
not a two-dimensional array, which is what the OP wants.

Brian
Boni - 05 May 2005 17:55 GMT
> No, the above line is invalid.
> and this line is also invalid.
Hi Brian,
thanks to pointing that out. I am sorry for that advice.
> Ah, but that's not the same, is it? You have created an array of pointers,
> not a two-dimensional array, which is what the OP wants.
I think you are wrong on that. There is physically no such thing as a 2
dimentional array in the memory. It is array of pointers to pointers. The
first operator[] take the pointer to the array of values the second
operator[] takes the value.
With best regards,
Boni
Brian Muth - 05 May 2005 22:27 GMT
And thank YOU for refreshing by C skills!

Brian
Brian Muth - 04 May 2005 19:53 GMT
MyClass (*m_MyClass)[4][8];

Brian

> Hello,
>
[quoted text clipped - 12 lines]
>
> Eitan
Eitan - 04 May 2005 21:10 GMT
Thanks, Eitan

> Hello,
>
[quoted text clipped - 12 lines]
>
> Eitan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.