Hacker News new | ask | show | jobs
by NateDad 4043 days ago
As jerf said - the embedded struct, while exposed to users of the external struct, still has no access to anything in the external struct. You can't override the methods it calls, etc. All the methods it calls will always be its own methods, never one from the external struct.

Inheritance implies is-a, and implies that you can modify some of the internal workings of the class you're inheriting from.

Embedding is strictly has-a. It's really no different than having a member variable in any other language... there's just some syntactic sugar to make it a little nicer to access the member's methods and fields (and the methods "count" for fulfilling interfaces).