Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    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?

  • #2
    Regular Coder
    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")};
    I know, it is dutch, but I hope you get the point.

    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;
    CString is just a class I used as an example

  • #3
    New Coder
    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.

  • #4
    New Coder
    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.

  • #5
    New Coder
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •