May 2002
Beginner
320 pages
6h 18m
English
One of the interesting capabilities offered by allocating structures from the heap is that you can use a pointer in the structure to link structures together into a list (called a linked list). For instance, you can create an indefinitely long list of aTapeElement structures by adding a member variable to aTapeElement that is a pointer to the next aTapeElement:
struct aTapeElement
{
char Operator;
float Operand;
aTapeElement *NextElement;
} ;
Then you can link them together, like this:
1: aTapeElement Tape; 2: aTapeElement SecondElement = new aTapeElement; 3: Tape.NextElement = SecondElement; 4: aTapeElement ThirdElement = new aTapeElement; 5: Tape.NextElement->NextElement = ThirdElement; ...
Read now
Unlock full access