? about C arrays

This is a discussion on ? about C arrays within the C++ Programming forums, part of the General Programming Boards category; Hello, I've been searching the code for the definition of the bond_cashflow array, a class array: bond_cashflow but havn't been ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    12

    ? about C arrays

    Hello,

    I've been searching the code for the definition of the bond_cashflow array, a class array:

    bond_cashflow

    but havn't been able to find a specific array creation statement, ie something like:

    BondCash[] bond_cashflow

    but only see this statement:

    amt_flow = new bond_cashflow [1];

    ? does the statement above automagically create the "bond_cashflow" array?

    thanks very much for any insights!
    bobK

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    Well in order for this to be valid C++:

    bond_cashflow * amt_cashflow;
    amt_cashflow = new bond_cashflow [1];

    bond_cashflow would need to be a type and the result would be an array called "amt_cashflow".

    Now why have you created an array of one element?

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    12
    Yes that is the way that:

    amt_flow

    is defined

    Bond_cashflow * amt_flow;

    So by making "amt_flow" a pointer to a "Bond_cashflow" class, it allows one to treat the Bond_cashflow class as if it were a member of an array?

    bk

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    With the mention of class and new, I believe that this question has to do with C++, not C.

    Moved to C++ forum.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    Well what are you really doing? The appropriate time for new[] (or malloc in C--I'm still not sure what language you're using) is when you need to allocate a resource, like an array of a certain type. Any other use for new[] is wrong.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by bobk544 View Post
    Yes that is the way that:

    amt_flow

    is defined

    Bond_cashflow * amt_flow;

    So by making "amt_flow" a pointer to a "Bond_cashflow" class, it allows one to treat the Bond_cashflow class as if it were a member of an array?

    bk
    Um ... I think you have that backwards. You're not treating the class as though you it is part of an array, you're making a whole new thing, and that thing turns out to be an array of Bond_cashflows. It doesn't change what a Bond_cashflow is itself.

  7. #7
    Registered User
    Join Date
    Feb 2005
    Posts
    12
    ok thanks all i'm going to look at this some more and try to create a small protype, appreciate the very considerate help!

    bk

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    BondCash[] bond_cashflow
    If you're just looking for ordinary array-declaration syntax, it looks like this:
    Code:
    type array_name[size];
    In your case, that would be:
    Code:
    BondCash bond_cashflow[SIZE];
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 06:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 03:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 09:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM

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