Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!spool.mu.edu!samsung!usc!elroy.jpl.nasa.gov!ames!vsi1!daver!tscs!tct!chip From: chip@tct.uucp (Chip Salzenberg) Newsgroups: comp.lang.c++ Subject: Re: Co-ordinating the polymorphism in C++ Message-ID: <27BFD8E3.3D1D@tct.uucp> Date: 18 Feb 91 13:38:42 GMT References: <1991Feb11.003849.27340@gpu.utcs.utoronto.ca> <600@taumet.com> <1991Feb13.011731.10114@gpu.utcs.utoronto.ca> Organization: Teltronics/TCT, Sarasota, FL Lines: 59 According to craig@gpu.utcs.utoronto.ca (Craig Hubley): >Overloading *is* a form of polymorphism, albeit a static one. I agree. >This is no different that building three types that inherit the same >virtual function. I disagree. Overloading is a static phenomenon limited to compile time, and that fact is visible to the programmer. For example, given a base class B and a derived class D: extern void foo(B&); extern void foo(D&); D d; B& b = d; foo(b); It is the "foo(B&)" function that will be called, the decision being based on the _static_ type of the argument. Likewise, given a non-virtual member function "foo()" defined in both B and D [no pun intended!]: D d; B& b = d; b.foo(); It is B::foo() that is called, this decision being made in a way very similar to the resolution of overloaded functions. In contrast, virtual function resolution is a _dynamic_ phenomenon. Were foo() made virtual, however, the decision between B::foo() or D::foo() -- or even some other, as yet unimagined, function E::foo() -- would be deferred until run time. So I conclude that it is NON-virtual member function resolution that correspond most closely to function overloading. >>Templates and polymorphism are orthogonal concepts. > >Templates are closely related to inheritance in that they are both >ways to create a family of types with similar behavior. The preprocessor is also a means to creating a class family; yet it is obviously unrelated to inheritance per se. As I understand templates, it is true that classes may be defined in template form, but so may anything, including non-member functions that could otherwise be part of an old C program, e.g. a generic qsort() comparison function. So templates and inheritance _are_ truly orthogonal. >"Orthogonal" in the sense that they can be implemented separately, but >not in terms of how they interact to the user. Again, though, templates are a purely static phenomenon. They are utterly unlike virtual functions, which are resolved at run time. -- Chip Salzenberg at Teltronics/TCT , "I want to mention that my opinions whether real or not are MY opinions." -- the inevitable William "Billy" Steinmetz