On Sunday, 3 August 2025 at 11:11:43 UTC, Brother Bill wrote:
In Programming in D book, page 247, it is written: Variables of struct and class types are called objects.

This struck me as odd and confusing. I have always been taught that objects are instances of classes. That is, new MyClass creates an instance or object of MyClass.

There was a wall between value types and reference types.
Of course structs and class types are both user defined types, but one with value semantics and the other with reference semantics.

Given that most languages support both user defined value types and user defined reference types, that D use the same term for both instances.

Am curious whether experienced D developers actually refer to both struct and class variables as "objects" without confusion.

Is this something that most D newbies struggle over?

Please assist with my "deprogramming" from "objects" being only for reference types.


Classes and structs in C++ are both value types, and instances of both are referred to as objects. This isn't unusual.

An object is a concrete instance of a type described by a class or struct definition. It's the thing you're manipulating, not the definition. Whether you're manipulating it directly or through a reference makes no difference. Whether it's on the stack or the heap makes no difference.

Consider that a pointer to a struct a reference to the struct instance in the same way a class variable is a reference to a class instance.

Reply via email to