Re: C++ templates and overloading

Robert A Duff <>
4 May 2000 17:17:06 -0400

          From comp.compilers

Related articles
C++ templates and overloading (Ugo) (2000-05-01)
Re: C++ templates and overloading (Robert A Duff) (2000-05-04)
Re: C++ templates and overloading (2000-05-08)
| List of all articles for this month |

From: Robert A Duff <>
Newsgroups: comp.compilers
Date: 4 May 2000 17:17:06 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 00-05-007
Keywords: C++, OOP

Ugo <> 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
error messages.

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.

- Bob

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.