Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Array of polymorphic objects of different dynamic type

6 views
Skip to first unread message

Ian Harvey

unread,
Dec 22, 2009, 3:33:43 AM12/22/09
to
Is it possible in F2003 to have an array that has elements with
different dynamic type at the same time?

My objective is to have a "list" of objects of common (abstract) parent
type, but different dynamic type (and each element in the array could
have different behaviour for a call to a particular deferred binding
procedure). The equivalent in a C++ sense would be an array of pointers
to class objects of the same base class, but different derived class.

I'm pretty sre the answer is no, and therefore what I have to do to have
an array of a second type that acts as a wrapper, forwarding any
relevant procedure calls to its single polymorphic component (or ditch
compiler provided arrays altogether and roll my own "list"). Seems like
a bit of a pain in the backside though. Alternative suggestions (or
answering "yes! - you do it this way..." to the initial question) welcomed.

Thanks,

IanH

e p chandler

unread,
Dec 22, 2009, 5:52:55 AM12/22/09
to

"Ian Harvey" <ian_h...@bigpond.com> wrote in message
news:Hv%Xm.63935$ze1....@news-server.bigpond.net.au...

I don't know about the procedureal end, but the data end of this makes me
think of variant records in Pascal. Each has a tag field which specifies the
actual record layout. If this is no help, then I'm sleepwalking.....

--- e


Richard Maine

unread,
Dec 22, 2009, 9:58:10 AM12/22/09
to
Ian Harvey <ian_h...@bigpond.com> wrote:

> Is it possible in F2003 to have an array that has elements with
> different dynamic type at the same time?

No. Type is a property of the array - not of each element separately.

> The equivalent in a C++ sense would be an array of pointers
> to class objects of the same base class, but different derived class.

Well, you also can't have an array of pointers. The usual workaround to
that is...

> I'm pretty sre the answer is no, and therefore what I have to do to have
> an array of a second type that acts as a wrapper,

Yep. That's it.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain

0 new messages