Home Segments Index Top Previous Next

641: Mainline

Now suppose that you provide a second file—one that also contains three cars. Your program allocates memory for three new class objects in addition to the memory previously allocated for three other class objects:

             0                   1                   2     <-- train 
             |                   |                   |         array 
             v                   v                   v         index 
     ------------------- ------------------- ------------------- 
----*-------------------*-------------------*-------------------*--- 
    |  First pointer    |  Second pointer   |  Third pointer    | 
 ---*-------------------*-------------------*-------------------*----  
             |                   |                   | 
             v                   v                   v 
     *-----------------* *-----------------* *-----------------* 
     | Fourth allocated| | Fifth allocated | | Sixth allocated | 
     | chunk of memory | | chunk of memory | | chunk of memory | 
     *-----------------* *-----------------* *-----------------* 
  
     *-----------------* *-----------------* *-----------------* 
     | First allocated | | Second allocated| | Third allocated | 
     | chunk of memory | | chunk of memory | | chunk of memory | 
     *-----------------* *-----------------* *-----------------* 

Now, however, there are no pointers to the first three of the memory chunks allocated at run time for class objects. Accordingly, those chunks are completely inaccessible.