473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Array of class and a pointer to it

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

Nov 17 '05 #1
6 980
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
"Eitan" <Ei***@discussions.microsoft.com> schrieb im Newsbeitrag
news:72**********************************@microsof t.com...
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

Nov 17 '05 #2
MyClass (*m_MyClass)[4][8];

Brian

"Eitan" <Ei***@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
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

Nov 17 '05 #3
Thanks, Eitan

"Eitan" wrote:
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

Nov 17 '05 #4

"Boni" <oilia@nospam> wrote in message
news:#J**************@tk2msftngp13.phx.gbl...
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

Nov 17 '05 #5
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
Nov 17 '05 #6
And thank YOU for refreshing by C skills!

Brian

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
10
by: amparikh | last post by:
Ok, my question is not about Virtual destructors and why, but more on the significance. Generally we have a virtual destructor in the base class ( and inadvertently in the derived class) so that...
3
by: Kaz Kylheku | last post by:
Given some class C with array T x, is it possible to get a pointer-to-data-member to one of the elements? &C::x gives us a pointer-to-member-array: T (C::*). But I just want to get a T C::*...
1
by: Jeff | last post by:
I am struggling with the following How do I marshal/access a pointer to an array of strings within a structure Than Jef ----------------------------------------------------------------
9
by: shaun | last post by:
Dear all, I realized an error in a previous post, I reproduce it here because I'm still not sure how to solve it: I want to make a templated function which points to one-past-the-end of a...
1
by: Tomás | last post by:
Some programmers treat arrays just like pointers (and some even think that they're exactly equivalent). I'm going to demonstrate the differences. Firstly, let's assume that we're working on a...
14
by: Peter Hallett | last post by:
I would like to set up a string array as a class member, or field, and then populate this array by reading in from a text file, but I cannot find the appropriate syntax. The getter and setter are...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.