3 ms·
Basically, because not every class is used polymorphically, many are designed to be used primarily on the stack or as members. I also see classes used as membe
by stcredzero 17y ago
Basically, because not every class is used polymorphically, many are designed to be used primarily on the stack or as members.
I also see classes used as members in Smalltalk. I wonder if a language can make the use of these sorts of objects explicit? Seems like there should be a good opportunity for better optimization.
- pmjordan 17y agoThe problem with that (in C++) would be that A a; A* p = new A; assert(sizeof(*p) == sizeof(a)); This wouldn't be true and cause all sorts of trouble (arrays, etc.) if a had no pointer to a vtable, but *p did. Moreover, you can take the address of a stack/member object, so how would you distinguish the two types? You'd literally need to modify the type system, and that would cause trouble with templates, etc.
- stcredzero 17y agoI'm not thinking of this in C++ or Smalltalk. I'm thinking of a feature in another language.