help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ / multiple instances / iostreams


From: Detlef Vollmann
Subject: Re: C++ / multiple instances / iostreams
Date: Fri, 23 Jul 2004 11:04:37 +0200

Hans Aberg wrote:
> Yes, one builds a hierarchy of classes, all derived from one root class --
> which I called class object_root. If you want to put a class of any kind
> into this polymorphic hierarchy, then make a virtual derivation from the
> root class, like:
>   class my_class : public virtual object_root {
>     ...
>   };
> Then the class object that maintains a reference-counted pointer to
>   object_root* data_;
> also has functions
>   object_root* data() { return data_; }
>   const object_root* data() const { return data_; }
> Thus, a typical Bison .y action might look like:
>   my_class& mc = dynamic_cast<my_class&>(*$5.object_.data());
> or
>   my_class* mcp = dynamic_cast<my_class*>($5.object_.data());
>   if (mcp == 0)  error();
Ok.  That's fine.

> 
> I can also build an object class maintianing a pointer to my_class:
>   class my_object_class {
>     my_class data_;
>     ...
>     object_root* data() { return data_; }
>     const object_root* data() const { return data_; }
>     ...
>   };
That was the part that was what was not clear to me.
As long as you don't dynamic_cast between different kinds of
my_object_class, your code is fine.

Detlef

-- 
Detlef Vollmann   vollmann engineering gmbh
Linux and C++ for Embedded Systems    http://www.vollmann.ch/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]