Quote:
The initialization of A will dereference the entire object pointed to by pClass, which means that all of its members will be copied from the heap to the stack. Does the same happen in the initialization of B? Or is the initialization of B less costly because only one member of the object will be dereferenced?
No it doesn't!
Dereferencing a pointer does not copy anything anywhere: and certainly not onto the stack! Think about it: the heap is several GB, each stack in probably around 1MB or less. You can't dereference a pointer ad copy the object onto the stack. All that happens when you dereference a pointer is that you "follow it" to the destination item.
Think of a pointer as the index in a book: you look up "CodeProject" in the index and it says "page 123, line 14, word 6". You open the book at page 123, count down lines to 14, then count words to 6 and there is the word "CodeProject". You haven't copied the book in whole or in part - you have just dereferenced the index pointer to get to the data item.