Thread: Arrays of objects

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    39

    Arrays of objects

    How can I do the following?

    Code:
        
    Student *sa[3];
        
    *sa[0] = new Student("James");
    *sa[1] = new Student("Jason");
    *sa[2] = new Student("Frank");
    Ohh and the name has to supplyed at runtime.
    Last edited by (Slith++); 07-11-2006 at 12:42 AM.

  2. #2
    Registered User
    Join Date
    Jan 2006
    Location
    Seattle
    Posts
    30
    Code:
        
    Student *sa[3];
        
    sa[0] = new Student("James");
    sa[1] = new Student("Jason");
    sa[2] = new Student("Frank");
    You should be able to figure out how to supply the name at run-time unless there's some specific problem that's going to occur but from the minuscule information you provided I'm not sure how to know what's really going on in your program.
    Last edited by Peter5897; 07-11-2006 at 12:51 AM.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    39
    I swear I tryed that. Ohh well works now.

    Thanks very much

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    135
    Quote Originally Posted by (Slith++)
    How can I do the following?

    Code:
        
    Student *sa[3];
        
    *sa[0] = new Student("James");
    *sa[1] = new Student("Jason");
    *sa[2] = new Student("Frank");
    Ohh and the name has to supplyed at runtime.

    You don't need the dereference operator on each element. Remove them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Replies: 60
    Last Post: 12-20-2005, 11:36 PM
  4. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:57 PM
  5. sorting arrays
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 10-13-2001, 05:39 PM