[antlr-interest] static casts in heterogeneous AST parser
braden at endoframe.com
Tue Oct 9 01:33:42 PDT 2001
On Mon, 2001-10-08 at 15:48, Ruslan Zasukhin wrote:
> on 10/8/01 19:06, John Lambert at johnl at jbase.com wrote:
> > I have problems compiling a parser using heterogeneous ASTs on HPUX.
> > It is objecting to all static_cast operations between ASTRefcount<AST> and
> > ASTRefcount< derivedAST>
> > HP support claim they are correct and that it should be a reinterpret_cast. I
> > disagree, this works fine on lots of other platforms and a quick test of
> > reinterpret_cast on other platforms produces compilation errors.
> > Has anyone else encountered this ?
> If I am not mistake (and I think I am not) rule is next:
> if a class has at least one virtual function
> then e must use dynamic_cast<>, otherwise static_cast<>
No, the rule you're thinking of is that in order to be able to use
dynamic_cast, the class must have at least one virtual function.
A dynamic_cast is a run-time cast. It is useful when the complete type
of an object cannot be known at compile-time (or if certain properties
of the complete type cannot be resolved by the compiler). Of course, a
static_cast is a cast that is performed at compile time. Most common
casting needs are met by static_cast.
> This is annoying frankly saying...
> Let I have class A with no virtual functions and use it in a lots of places.
> Later if I will need virtual function in this class, all static_cast for it
> must be replaced on dynamic_cast<>.
This is not the case.
Braden McDaniel e-mail: <braden at endoframe.com>
<http://endoframe.com> Jabber: <braden at jabber.org>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest