|C++ templates and overloading email@example.com (Ugo) (2000-05-01)|
|Re: C++ templates and overloading firstname.lastname@example.org (Robert A Duff) (2000-05-04)|
|Re: C++ templates and overloading email@example.com (2000-05-08)|
|From:||Robert A Duff <firstname.lastname@example.org>|
|Date:||4 May 2000 17:17:06 -0400|
|Organization:||The World Public Access UNIX, Brookline, MA|
Ugo <email@example.com> writes:
> I'm designing a compiler for a proper subset of C++ which includes
> - function templates
> - overloading of functions
> I'm looking for some resources which talks about this problem, i.e.
> polymorphism/overloading in IMPERATIVE languages.
I believe that in C++, you can do overload resolution of function
calls in a single bottom-up pass over each statement. (I'm assuming
your parser builds a tree, which semantic analysis can then walk.)
For a function call F(...), first resolve all the arguments, which
determines their types. Then look up F in your symbol table, to get
the set of all visible F's. Throw away all the F's that have the
wrong parameter types. If you're left with exactly one F, then that's
the one to call. If you're left with zero, or more than one F, it's
an error. You probably want to do some special-casing to get decent
C++ allows various implicit type conversions, which complicates the
In Ada, overload resolution requires *two* passes over each statement
(bottom-up, then top-down), because in Ada, the result type of a
function participates in overload resolution. Similarly for the
result type of a literal -- you can have overloaded enumeration
literals, for example. I prefer the Ada rule over the C++ rule.
Return to the
Search the comp.compilers archives again.