[Prev][Next][Index][Thread]
Re: Students/techniques
On Tue, Jun 6, 2000 9:15 Uhr, Hugh Greene <mailto:q@tardis.ed.ac.uk> wrote:
>While brushing up my C++ recently, I realised that C++ actually does have
>"generic functions" in one particular limited case: overloaded global
>operator methods, like operator+. In fact, you can even reproduce Dylan's
>"ambiguous method" problem by
>
Overloading in C++ works not only with (a hand-picked subset of) built-in
operators, but also with user-defined functions in general.
But this kind of overloading lacks the full power of generic functions,
because method selection is done at compile time, based on the static
(-ally inferrable) type of the arguments, not by the dynamic type of the
objects. Virtual methods allow dynamic dispatch on the single and arbitrary
receiver object.
The only area where C++ really shines are templates, since the template
selection rules contain type based lookup and incorporate a prolog-like
sublanguage that can be used for metaprogramming.
Gabor
Follow-Ups: