473,403 Members | 2,270 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,403 software developers and data experts.

An array containing an array and simple types?

Hi all,

I'm banging my head over this one but there's got to be an easy answer!
I have a library of books. Each book has simple types: string sTitle, string sAuthor, boolean bIsHardback
but a book also has a number of pages. A page must exist(there may be >1) and pages need a number of simple types: string sPageText, boolean bHasImage.

My logic says this works:

Expand|Select|Wrap|Line Numbers
  1. class APage
  2.     {  // A single page
  3.         public boolean bHasImages;
  4.         public string sPageText;
  5.     }
  6.     class ABook
  7.     {   // Object to hold pages 
  8.         string sTitle;
  9.         string sAuthor;
  10.         boolean bIsHardback;
  11.         APage[] BookPages;
  12.     }
  13.  
When I try this, I can't work out how to initialise the inner array (APages). I've tried

Expand|Select|Wrap|Line Numbers
  1. APage()
  2. {
  3. APage[]=new APage[1];
  4. }
as initialiser in the APage class but clearly, I'm missing something obvious. Can anyone help an ex-Pascal guy get his head around this? ;-)
Oct 5 '10 #1
2 1213
GaryTexmo
1,501 Expert 1GB
You're close!

Expand|Select|Wrap|Line Numbers
  1. APage()
  2. {
  3.   BookPages = new APage[1];
  4. }
Looks like a bit of a typo... long day? Been there :)

If your book is intended to have any number of pages, might I recommend using a list instead?

Expand|Select|Wrap|Line Numbers
  1. List<APage> BookPages = new List<APages>();
It's a little easier to work with in my opinion.
Oct 5 '10 #2
Doh! Do I feel stoopid right now ;-)
Thanks for spending the time on something so very trivial, Gary!
Like the idea of the List - thanks for the heads-up on that one.
Oct 6 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Nicolay Korslund | last post by:
Hi! I'm having a little trouble with the typecast operator, can anybody help me with the rules for when the this operator is invoked? In the class 'Test' in the code below, the typecast operator...
8
by: kings_oz | last post by:
I have an array or items each item in the array can contain another array of other items and that array of other items can contain more array of item. I want recursively iterate through the array...
7
by: Eric Boutin | last post by:
Hi ! I would like to generate an array of type char; I just dont really figure out how I could do it with malloc or calloc.. I mean.. I know how to allocate a simple array with both of them;...
2
by: Schnogge | last post by:
Hi! it is possible to generate an multiple-dimensional array with different data types? Or is it possible to combine a one-dimensional array with an other which has an other data type? How...
2
by: BartMan | last post by:
Greetings, When working with managed c++, do you have to do anything special when going from simple types from managed to unmanaged and vice versa. Or is marshalling handled automatically for...
2
by: cindy | last post by:
i build a string string eProduct = "#blah#ablah#bbbb"; StringBuilder sb = new StringBuilder(eProduct); eProduct = sb.Replace("#","").ToString(); string aProducts= eProduct.Split(';'); then I...
4
by: Dmytro Bablinyuk | last post by:
I came across several possible ways of allocating memory for objects, for example: 1. malloc(sizeof(T)*3)/free - raw memory 2. new T/delete - buffer would be initialized to...
8
by: nobrow | last post by:
Okay ... Im out of practice. Is it not possible to have a 2D array where each column is of a different type, say an int and a struct*? The following seg faults for me and I cant figure out what I...
8
by: =?big5?B?r0W84Q==?= | last post by:
Hi All C gurus: Below is a small program to print out the address of array and address of array variable: int main() { char array = "haha"; printf("array:%x\n", array); printf("&array:%x\n",...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.