Topic: Compiler-generated methods (Was: Comments on Simple List Design)


Author: jbn@lulea.trab.se (Johan Bengtsson)
Date: 1 Jul 92 12:55:52 GMT
Raw View
sasha@ipm.msk.su (Alexander Kolbasov) writes:
:
: I may suggest another List implementation. Any list element should derive
: from the class Object which is not very restrictive: [...]
:
: class Object
: {
: public:
:   virtual           ~Object() {};
:   virtual classType  typeOf() const { return OBJECT_TYPE; }
:   virtual Object&    copyOf() const { return *new Object; }
                                          -------------^
                                          Should be Object(*this) or pure virt.
: };

Although templates make the "everything inherits from class Object"
approach somewhat obsolete, I think the above three methods should be
present in any base class that has virtual functions.

The C++ standard I believe will include typeOf() (dtype()?) for all classes.

Questions:

1) If the compiler automatically generates a typeOf() function,
   why not go ahead and also have it generate a copyOf() function?
   It is trivial and tedious to implement by hand.  Also, the compiler
   could generate an empty virtual destructor, unless an explicit
   destructor is declared.

2) Are there more "standard" methods that could be generated like this?

3) How will standard C++ handle typeOf() for classes that have no
   virtual member functions?  C compatibility seems to preclude
   virtual behaviour for such classes.

--
--------------------------------------------------------------------------
| Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
| Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490  |
--------------------------------------------------------------------------