Dynamic Array of Object Fucntion call.

This is a discussion on Dynamic Array of Object Fucntion call. within the C++ Programming forums, part of the General Programming Boards category; Can someone please help me with the piece of code... cout << "How many items would you like to enter ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    Question Dynamic Array of Object Fucntion call.

    Can someone please help me with the piece of code...


    cout << "How many items would you like to enter in the inventory?";
    int arrayLen = reader2.readInt();

    Menu *itemArray;
    itemArray = new Menu[arrayLen];

    for(int t=0; t<arrayLen; t++)
    {
    itemArray[t].newItem;


    }

    It skips over itemArray[t].newItem;
    not sure how to fix this???

    I would be thankful for any help.

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    It doesnt do anything. You arent telling the program what to do with it...

    What is it you want it to do.
    What is C++?

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    2
    I am trying to create a array of Menu objects with a array size picked by the user...
    then run though each of those objects in the array and run the newItem fucntion witch is part of the Menu object.

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Code:
     itemArray[t].newItem();
    I think thats probably what your trying to do.
    If not post where newItem is defined.

    [note]
    also, welcome to the boards.
    For future post
    << !! Posting Code? Read this First !! >>.
    There you will see how to use code tags. They make your code much easier on the eyes
    What is C++?

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    itemArray = new Menu[arrayLen];
    I think it's can change like this:
    Code:
    itemArray = new Menu[arrayLen+1];  //gave a space for the  '\0'
    maybe this is not error point.

  6. #6
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    You only need the null character to terminate character arrays. I doubt it would be useful for an array of Menu objects, however they are defined.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  2. Multi-dimensional dynamic array - performance
    By melkor445 in forum C++ Programming
    Replies: 15
    Last Post: 10-07-2007, 05:17 AM
  3. Dynamic structure with array and array count
    By Nazgulled in forum C Programming
    Replies: 14
    Last Post: 06-08-2007, 11:10 PM
  4. Replies: 4
    Last Post: 11-02-2006, 11:41 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21