[Top][All Lists]
[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/
- Re: C++ / multiple instances / iostreams, (continued)
- Re: C++ / multiple instances / iostreams, Hans Aberg, 2004/07/24
- Re: C++ / multiple instances / iostreams, Detlef Vollmann, 2004/07/24
- Re: C++ / multiple instances / iostreams, Hans Aberg, 2004/07/25
- Re: C++ / multiple instances / iostreams, Detlef Vollmann, 2004/07/25
- Re: C++ / multiple instances / iostreams, Hans Aberg, 2004/07/26
- Re: C++ / multiple instances / iostreams, Detlef Vollmann, 2004/07/26
- Re: C++ / multiple instances / iostreams, Hans Aberg, 2004/07/27
- Re: C++ / multiple instances / iostreams, Detlef Vollmann, 2004/07/28
- Re: C++ / multiple instances / iostreams, Hans Aberg, 2004/07/28
- Re: C++ / multiple instances / iostreams, Hans Aberg, 2004/07/22
- Re: C++ / multiple instances / iostreams,
Detlef Vollmann <=
- Re: C++ / multiple instances / iostreams, Hans Aberg, 2004/07/23
- Re: C++ / multiple instances / iostreams, Detlef Vollmann, 2004/07/24
- Re: C++ / multiple instances / iostreams, Hans Aberg, 2004/07/24
Re: C++ / multiple instances / iostreams, Oliver Kowalke, 2004/07/19
RE: C++ / multiple instances / iostreams, Urdaneta, Alfonso E (N-Summitt Technologies), 2004/07/22