Hi,
This might very well be a C question. I am posting it here because it refers to some code in Bruce Eckels's 'Thinking in C++'. Apologies if this causes any inconvenience.
There is a struct definition, and use thereof, on p.248-250 that confuses me.
Within struct Stack, he defines the nested struct:
Code:
struct Link {
void* data;
Link* next;
void intialize(void* dat, Link* nxt);
}* head;
Then, in the associated function Stack:ush(void* dat);
he creates a Link like this:
Code:
Link* newLink = new Link;
newLink->initialize(dat, head);
head = newLink;
There are a couple of things that I don't follow here.
Firstly, he has not needed to call Link like this:
Code:
struct Link newLink......
I was sure that a struct had to be initialized with an explicit struct definition unless it was typedeffed into the word between } and ; at the end of the struct. Was I completely wrong?
Does he say on p.230-231 that this is a difference between C and C++ ? (I am not confident enough at either to tell for sure).
Secondly, the word between } and ; here is * head. But * head is not a type definition in this case. Rather it is a particular instance of Link, namely the access point to the single-linked list for the container class. He says this is a legacy from C.
*head in this case, seems to be just a particular instance of a Link. Is this what is taking place?
Apologies again if this is in the wrong place. But part of the problem is that I am not sure what is C and C++ here. It is a nice example in Eckel, and I would like to use similar code myself, but I don't yet understand it.
Thanks!