From: Stefan S. <se...@sy...> - 2004-06-10 01:52:03
|
Hi Grzegorz, Grzegorz Jakacki wrote: > You restrict yourself to modelling IsA by derived-to-base conversion. I try to avoid having to define and implement my own type system. C++ already provides one for us, so why not delegate all the related work to the C++ runtime (RTTI) and the compiler ? I'm not (yet) convinced that the limitations of such an approach outwight the advantages. > struct PtreeBinaryOp : public NonLeaf > { > PtreeBinaryOp(Ptree* l, Ptree* r) : NonLeaf(l, r) {} > }; Why isn't the 'BinaryOp' part of the high level API ? If it was, it could have three members to directly access the operator as well as left and right operands: struct BinaryOperator : public NonLeaf { //. add appropriate constructor(s) const Ptree *get_operator() const; // instead of 'const Ptree' this could return a typed subclass Expression *left(); Expression *right(); }; by the way: if this returns a Ptree, it has to be const, so users can't modify it to become something other than a binary operator. As Expressions would hide the un(type)safe Ptree API, they don't need to be const, i.e. users can modify them as long as it remains an Expression. > // Fourth part of high-level API is a dispatcher -- > // a mechanism that lets you find out more detailed > // type information about node (e.g. you pass > // Node<Expr>, and dispatcher calls, say, > // v.Visit(Node<Plus>), if your Node<Expr> was indeed > // a plus expression). yes, I think this is the central point we are disagreeing on: if we don't use the C++ type system, we have to build our own. That's quite heavy and I don't see any advantage in such an approach. Regards, Stefan |