|
![](/i/fill.gif) |
Warp wrote:
> However, can this be called object-oriented? Having objects in an array
> excludes the possibility of using objects of a derived type (unless an
> object of the derived type has the exact same size as the base type object;
> even then it requires some low-levelish trickery to get it working, at
> least in C++, and probably other languages where objects can be handled
> by value and put into arrays). However, one of the basic ideas of OOP is
> that whenever an object of type A is expected, an object of type B can be
> given to it instead, if B has been derived from A (or from any of its
> subclasses). An array of objects wouldn't support this.
Wouldn't you just need to determine the storage requirements of THE
LARGEST class of object? And allocate that amount for every object?
Granted, I don't actually know of a language or compiler which actually
supports this...
(In particular, if you can add new subclasses dynamically at runtime,
this approach obviously won't work at all. But if all classes are known
at compile-time, it's feasible in principle.)
Post a reply to this message
|
![](/i/fill.gif) |