|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> Actually, wouldn't this be clearer to do with virtual functions or pointers
> to functions anyway? Where does typeid make things better in that scenario?
> Isn't it just as easy to do something like
> class Alpha : Beta {
> ....
> virtual const char * me() { return "Alpha:Beta"; }
> ....
> }
It was you who complained that you have to write a "mySize()" function
in every single class derived from the base class if you wanted any useful
information about the actual object. I thought you wanted some way of
distinguishing the actual object without having to implement a function
in each class.
> Plus, you avoid the overhead of putting
> RTTI type_info on *every* class, most of which probably won't be registered
> that way?
If you have a virtual function in the class or any of its parent classes,
you already have RTTI info on it. typeid() itself doesn't add anything to
the classes.
It's also perfectly possible to ask for the typeid of a non-RTTI class
(ie. one which does not have any virtual functions). In that case you
simply get the typeid of the parameter (without the runtime checking of
whether the object is really of that type).
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |