This is my answer to this question.
The last two compilation errors are fairly straight-forward. Even though stock has << operator overloading. Neither snhas nor snst has << overloading implemented. If we want to print the stock, we need to change it to cout << snhas.stk and cout << snst.stk
However, cout << snis works fine. Well, that's the working of inheritance (is-a relationship). snis IS A stock and stock supports << operator. Therefore, operator << works with snis.
snhas.stk.setstock(...) compilation error
Then, what happens to the snhas.stk.setstock(...) compilation error? It seems like we can do snis.setstock(...) and snst.stk.setstock(...). The compiler error message gives the clue that says "stk is private".... Can you go back to quiz and figure it out?
Ya, look at our snhas definition again, the class member setstock() is "private" by default. Private members can not be accessed directly by users (like our test program). On the other hand, the struct members is default to public. That's why snst.stk.setstock(...) works.
After fixing the issues, here is the run result.
size of different stockNode
A stock node has 16 bytes. All three sotckNode types have 32 bytes, which is the size of stock object plus two pointers (16+8*2). Note that I am running it on 64-bit Mac, so the size of a pointer is 64 bits (8 bytes). If you run on a 32 bit machine, the pointer size should be different. In fact, all three stockNode types have identical data fields (shouldn't be a surprise). Every stock data member has a space in stockNode.