Newsgroups: comp.lang.c++
Path: utzoo!utgpu!craig
From: craig@gpu.utcs.utoronto.ca (Craig Hubley)
Subject: Co-ordinating the polymorphism in C++
Message-ID: <1991Feb11.003849.27340@gpu.utcs.utoronto.ca>
Organization: UTCS Public Access
Date: Mon, 11 Feb 91 00:38:49 GMT

Now that C++ has three polymorphism mechanisms
	- overloading		(compile-time)
	- templates		(link-time)
	- virtual functions	(run-time)

Is anyone thinking about how to reconcile them ?  As it stands now, I can
use overloading to add extra arguments to functions, etc., but I can't do
it in my derived classes because virtuals can't be overloaded, etc.

It seems to me that each of these three mechanisms have grown up in an
implementation-driven environment.  The user cares only about having
types/classes/whatever you care to call 'em that act predictably.  The
programmer cares only about minimizing the work required to create something
new.  But it seems as if all this has been designed to minimize the work of
the compiler writer, something which failed miserably in C.  As it's often
said, it's "easy to write a mediocre C compiler, very hard to write a good
one".  

To propose one small change, if virtuals could be overloaded in type-
compatible ways (i.e. redefining acceptable rguments as pointers to base 
classes in place of pointers to base classes, returning pointers to derived 
classes in place of pointers to base classes, and permitting extended
argument lists where defaults have been provided) this would add no more
work to the compiler than a simple decision to exhaust matching on virtual
functions before trying for an exact match at a different level, and no
overhead at all to user programs that did not use these features.

In effect it is no more than removing some arbitrary constraints on typing
that are inconsistent with the rules in the rest of C++, which is exactly
the kind of change we have been seeing between versions of C++.

I had a longer post on how/why this is so, with examples, but a crash seems
to have eaten it, so I'll elaborate later if this generates some interest.
-- 
  Craig Hubley   "...get rid of a man as soon as he thinks himself an expert."
  Craig Hubley & Associates------------------------------------Henry Ford Sr.
  craig@gpu.utcs.Utoronto.CA   UUNET!utai!utgpu!craig   craig@utorgpu.BITNET
  craig@gpu.utcs.toronto.EDU   {allegra,bnr-vpa,decvax}!utcsri!utgpu!craig
