Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 5 of 5
Thread: Arrays of Class Objects?

10132002, 09:13 AM #1
 Join Date
 Oct 2002
 Location
 middle of nowhere
 Posts
 34
 Thanks
 0
 Thanked 0 Times in 0 Posts
Arrays of Class Objects?
I'm writing a routine to calculate prime numbers and basically I need to build and access a table of class objects. Do I have to use a pointer or what?

10132002, 06:04 PM #2
 Join Date
 Jul 2002
 Location
 Belgium
 Posts
 124
 Thanks
 0
 Thanked 0 Times in 0 Posts
not necessarily(sp? though word to write). If you know how much objects you're going to need, you can do it like this
Code:CString zin[3]={CString("persoon 1"),CString("persoon 2"), CString("persoon 3")};
if you don't know how much objects you'll need, you'll have to use a pointer
Code:CString *multiple; multiple=new CString[5]; delete []multiple;

10142002, 01:06 PM #3
 Join Date
 Sep 2002
 Location
 Up North (UK)
 Posts
 46
 Thanks
 0
 Thanked 0 Times in 0 Posts
Shawn,
If you are using MFC then you can use the class CArray to manage the whole array. It will dynamically increase the size of the array when required.
Stuart.

10142002, 03:33 PM #4
 Join Date
 Oct 2002
 Location
 middle of nowhere
 Posts
 34
 Thanks
 0
 Thanked 0 Times in 0 Posts
I've only been programming for about 4 months now and I really dont know that much about the MFC yet. Are there any good references on how to implement the CArray class?
I was able to implement the array with a fixed array size, however to compute extremely large prime numbers(200 digits) I need to generate a very LARGE table of primes to check. I'm sure theres some f(x) showing the number of prime numbers between 2 and a given size(as the number size increases, there are less and less prime numbers). The major problem is that to actually compute a 200 digit prime, there must be billions of prime numbers to check against. I plan to implement a relevancy table(it only has to check certain primes for a given number size, therefore I can elimate extraneous candidates from the computation of the next prime, and add them only when they become neccessary). However, the 200 digit prime would have to dump the table to a file on disk, since there would be SO many prime candidates it actually has to check to verify that the number is indeed a prime number.

10152002, 08:52 PM #5
 Join Date
 Sep 2002
 Location
 Up North (UK)
 Posts
 46
 Thanks
 0
 Thanked 0 Times in 0 Posts
Shawn,
I don't fully understand why you are implementing CArray. If you actually talking about creating an instance of the CArray class, then I have found an example here.
I hope this helps, if not come back.