Suppose you have a node declared like this:
struct node
{
int data;
node * next;
};
and a list class declared like this:
struct myList
{
node * head;
node * tail;
int numNodesInList;
//member functions etc, but no other member variables.
};
Then what is the size of a myList object? Is it the size of three pointers (two member variables and the this pointer) plus the size of an int or is it the size of a node pointer or is it numNodesInList times the size of a node?
The reason I ask is a recent thread involved using an array of list objects and one of the people posting in that thread indicated that this:
myList array[10];
involved storing the head node of 10 myList objects in an array whereas I was skeptical of the entire construct because I felt there was no way of knowing the size of a list object because there is no way of knowing what the value of numNodesInList is at compile time.
However, now that I've had more time to think about this I suspect that the true answer is that the size of a myList object as declard above is the size of three pointers and an int. I am now reasonable comfortable with the idea that the number of nodes in the list and the memory each node takes up is relevant when contemplating how much memory the list uses in RAM, but the number of nodes in the list is not relevant when it comes to determining how much memory would need to be allocated to declare an array of lists (which would be the number of elements the array could hold times the memory needed to declare one element in the array), and that an array of myList objects as proposed by the initial poster does actually make sense.
I am happy to entertain any corrections or further discussion.