Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • "the reason structs cannot be inherited is because they live on the stack is the right one" - no, it isn't the reason. Commented Nov 18, 2021 at 1:55
  • 1
    A variable of a ref type will contain a reference to an object in the heap. A variable of a value type will contain the value of the data itself. The size of the data must be known at compile-time. This includes local variables, which includes parameters, which all live in the stack. Thinking about it the size of all object fields must be known during object allocation as well. So, I accept the stack a special case of a general reason, but it is still a reason, though. Commented Nov 18, 2021 at 15:26
  • 1
    When you put it that way, I agree. I was thinking about the other half of inheritance, where it is impossible to work with the data because the data doesn’t include a pointer to a class ref, so it is not knowable which subclass (sub-struct?) the data is from. Its just a meaningless sequence of bits. Commented Nov 18, 2021 at 19:13