The order of initialization is not determined by the order of initializers in the constructor initialization list, but by the order in which members are declared in the class' body.
If size
is declared below table
, then it gets initialized to zero after the memory allocation takes place. By the time table
is being initialized, size
still contains random garbage, and you are allocating an array of some random size. Your code exhibits undefined behavior.
You can fix the problem simply by writing table(new LinkedList<ItemType>[0])
. However, it's not clear why would you want to allocate an array of zero size in the first place. What good do you think that'll do you?
Rather than using a raw array and managing memory manually, consider using std::vector<LinkedList>
. And std::list
instead of home-grown LinkedList
, for good measure.