Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!visix!ip2020!adamksh From: adam@visix.com Newsgroups: comp.lang.misc Subject: Re: CHALLENGE: heterogeneous collections Message-ID: <1991Mar27.164605.24547@visix.com> Date: 27 Mar 91 16:46:05 GMT References: <1991Mar22.210725.29448@neon.Stanford.EDU> <48805@nigel.ee.udel.edu> <7689:Mar2623:28:5091@kramden.acf.nyu.edu> Sender: news@visix.com Reply-To: adam@visix.com Organization: Visix Software Inc., Reston, VA Lines: 35 In article <48805@nigel.ee.udel.edu> new@ee.udel.edu (Darren New) writes: >- Hmm... How about a window with a hetrogeneous collection of buttons, sliders, text displays, etc, all of which respond to "redraw" and "is the mouse over you"? >- In article <7689:Mar2623:28:5091@kramden.acf.nyu.edu>, brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >- struct { any object; void (*redraw)(); int (*ismouseover)(); } *whatsinwindow(); Here ``any'' is a polymorphic type (e.g., void * in C), and *redraw takes an ``any'' argument. Naturally, languages like C++ encapsulate the above struct into a single ``class,'' but that's merely syntactic sugar. >- Let me get this straight. To construct a heterogeneous list of M items each guaranteeing N operations, I need to waste space for M*N function pointers? Yes, we need to store ONE pointer to each function, but the above scheme wastes space if we have already stored that pointer, e.g. in a different kind of heterogeneous list. A large windowing application uses hundreds of different lists. And I need to write an explicit constructor for every kind of list? You can do better than that, even in C. Adam