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: Sat, 24 Jul 2004 11:40:39 +0200

Hans Aberg wrote:
> At 11:04 +0200 2004/07/23, Detlef Vollmann wrote:
> >>   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.
> 
> This may, by mistake, also happen, but then it shows up as a runtime error.
> Because of this, it is probably better to use the dynamic_cast<T&> form, as
> the code becomes simpler, and normally will not throw any exceptions. Any
> eventual exceptions can be traced with a debugger with such capacity.
In either case, you're in undefined behaviour territory here, as
my_object_class is not a polymorphic type as required by 5.2.7p6.
And undefined behaviour doesn't guarantee you a crash, but might
produce silently wrong results...

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]