Re: [Ctool-develop] using ctool as a library
Brought to you by:
flisakow
From: Stefan S. <se...@sy...> - 2003-08-01 18:04:32
|
Steven Singer wrote: > Stefan Seefeld wrote: > > virtual void traverse_base(BaseType *) = 0; > > virtual void traverse_ptr(PtrType *) = 0; > > virtual void traverse_array(ArrayType *) = 0; > > virtual void traverse_bit_field(BitFieldType *) = 0; > [etc.] > > Can I ask why all the functions have different names? Wouldn't it be > more natural to give them all the same name and then overload on the > argument type? mainly a matter of taste I guess. It's easier to distinguish. The single most important point is if you derive a new Traversal. If you use the same name for all methods, you have to redefine all of them (or specify 'using Base::traverse') or the compiler will complain. You may want to read about variations on this theme (and others) in John Vlissides' excellent book 'Pattern Hatching'. > If they all have the same name then instead of calling it traverse, > it could be operator(). Accept code could then look like: yes it could. But I find it much clearer to spell out what it is doing. I find 'operator ()' a little too compact. > I suspect a reference to a Traversal is more helpful than a pointer > as references can't be NULL and there's no need to rebind t partway > through a function. true. It's just lazyness as then you have to pass '*this' instead of 'this'. :-) Regards, Stefan |