|
![](/i/fill.gif) |
Invisible <voi### [at] dev null> wrote:
> Wouldn't you just need to determine the storage requirements of THE
> LARGEST class of object? And allocate that amount for every object?
No, because indexing is done based on the type of the array. For the
indexing to work properly the array type would have to be that of the
largest object type, but then you wouldn't be able to easily store any
other type of objects there (because now you would be handling objects
of the most derived class type rather than objects of the base class
type).
You could probably get around this limitation by creating an array
container class which handles the memory allocation and indexing using
low-level functionalities (raw pointer arithmetic and such), but it would
be quite a hack. And you wouldn't be able to use pointer arithmetic on
the array directly (except by using more abstract iterators).
Then there's the problem of assigning objects: If you assign an object
to a place in the array where there's already an object, and they are of
different types... I don't think it would work. Maybe you could get around
it by first destroying the existing object and then placing the new object
in its place using placement new, but it becomes complicated.
Perhaps not *impossible*, but as you may guess, quite hard and kludgey.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |