Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: asking an object for its type Message-ID: <71200@microsoft.UUCP> Date: 11 Mar 91 20:24:26 GMT References: <1991Feb20.232710.7843@ithaca.uucp> <1485@acf5.NYU.EDU> <71037@microsoft.UUCP> <27D57565.2B22@tct.uucp> <1991Mar7.153417.6489@linus.mitre.org> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 30 In article <1991Mar7.153417.6489@linus.mitre.org> dsr@mir.mitre.org (Douglas S. Rand) writes: |There is nothing which prevents a programmer from adding type testing |to C++ classes now. Many real programs require some of this. |You can add instance fields which get named in constructors, virtual |functions which return values, all kinds of perfectly acceptable |options are available to the programmer. Yes, one can do this, and many people are. Its just that currently it is ugly and inconvient to do so -- requiring at least some macro hacks. Thus, I say that C++ "enables" but does not "support" type testing. Its not necessary for type-testing to be built into the language in order for C++ to "support" it. The only requirement would be that some way be added to the C++ language to allow people who want to implement one or another type testing schemes to be able to do so cleanly and efficiently. The idea that I propose is that the capabilities of templates be enhanced so that template member function can be specified that are automatically expanded when inheriting from a class with such templated member functions. It seems that there is no way to use templates to accomplish this goal today. Type testing is thus just one example of what seems to me to be a weakness in templates: there seems to be no way to specify templated member functions o that are to be automatically implemented on all derivations. Again a simple example of this is to try to imagine a scheme where a "int SizeOf()" virtual function is to be implemented for all classes derived from some class "O" that needs the "int SizeOf()" method to be correctly implemented in all derived classes. Today, even with templates, the only way to get a correct SizeOf method implemented in each derived class is for the programmer to correctly and manually take some action to implement SizeOf in each derived class. Ugly, and error-prone.