Article View: comp.std.c++
Article #3429Re: Generic Object Callbacks
From: David Byrden
Date: Fri, 23 Feb 1996 17:55
Date: Fri, 23 Feb 1996 17:55
38 lines
2386 bytes
2386 bytes
>>>
What is needed is the ability to use member functions as callbacks
without any constraint on the type of the object they are invoked on.
This is possible in C++ only by using various implementation-dependent
hacks to escape the type system, because the language does not provide
any way to express such a construct.
<<<
The scheme presented by Richard Hickey in the C++ Report, Feb 95,
achieved this in what seemed to me an implementation-independent way.
Briefly; the creator of a functor would pass an object's and a function's
address to a template factory function; this would cause the
instantiation of various code, and return an object of a class Callback,
which would internally hold the addresses, the object address being
cast to void*.
The Callback object had an operator() which would take the various
parameters expected for the callback, and pass them to another function
generated by the Factory specialisation. This function would cast the
void pointer to the appropriate type for the object, and complete the
call.
No type information was shared between the caller and the called
modules, other than the declaration of various Callback classes and
associated functions. In fact, different Callback classes were required
to deal with functions having different numbers of parameters.
David
[ To submit articles: Try just posting with your newsreader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<4gkufu$akn@news.bridge.net>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<pgpmoose.199602221531.14635@isolde.mti.sgi.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: David Byrden <100101.2547@compuserve.com> Newsgroups: comp.std.c++ Subject: Re: Generic Object Callbacks Date: 23 Feb 1996 17:55:28 GMT Organization: self-employed Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <4gkufu$akn@news.bridge.net> References: <pgpmoose.199602221531.14635@isolde.mti.sgi.com> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Nntp-Posting-Host: ppp-mia3-116.bridge.net X-Mailer: Mozilla 1.1N (Windows; I; 16bit) X-Lines: 31 Content-Length: 1372 Originator: clamage@taumet