hvt@tnosel.UUCP (henq) (10/07/87)
Hi, In the recent debate on C++ vs. Objective-C, I read remarks like: "c++ does not provide dynamic binding, only virtual functions". Virtual functions seem very powerfull to me. You can write type-independant code with them like on page -37- of the Stroustrup book: shape_vec[i].rotate(45); Only at runtime can be determined what type of object occupies position [i] of shape_vec, that seems dynamic binding to me. What does 'real' dynamic binding offer you that virtual functions don't ? Has it something to do with the strict tree-like hierarchy of inheritance ? If c++ *does* privide dynamic binding, a runtime support for this must be generated by the pre-processor, right ? Can somebody please elaborate on this on the amateur level ? -Henk Have a nice day
tombre@crin.crin.fr (Karl Tombre) (10/12/87)
In article <481@tnosel.UUCP> hvt@tnosel.UUCP (henq) writes: > >In the recent debate on C++ vs. Objective-C, I read remarks >like: "c++ does not provide dynamic binding, only virtual functions". > Yes, C++ provides a limited dynamic binding with virtual functions. But it remains partially static because you have to define statically the subtree in which a given function has to be dynamically bound. For instance, you will say in a class Graphics : virtual void draw(); and draw() will be dynamically bound in all subclasses of Graphics. But if you don't say "virtual ..." the binding will be static, i.e. if you write Graphics x; x.draw() will always be the draw() function of class Graphics, if it exists, even when x is instance of say Triangle. Completely dynamic binding can be found in Smalltalk for instance, or Objective-C. This doesn't mean that it is desirable to have complete dynamic binding. For instance, in his book, Brad Cox gives the advice to use Abstract Classes with the implementedBySubclass selector. But in Objective-C or Smalltalk you are not COMPELLED to use this. Virtual functions seem to be a good idea, especially for people with a software engineering background. They can be found in one way or another in Simula-67, C++, Eiffel (deferred functions), Object-Pascal (Override), Beta etc. So the fact that this dynamic binding is restricted does not mean that it is a bad idea !! --- Karl Tombre @ CRIN (Centre de Recherche en Informatique de Nancy) EMAIL : tombre@crin.crin.fr -- tombre@crin.UUCP POST : Karl Tombre, CRIN, B.P. 239, 54506 VANDOEUVRE CEDEX, France PHONE : +33 83.91.21.25