Why is AbstractFunctionDeclaration not a Declaration? Why is ClassFunctionDeclaration not a FunctionDeclaration?

David Nolden zwabel at googlemail.com
Mon Mar 1 18:20:18 UTC 2010


Am Montag 01 März 2010 16:22:49 schrieb Milian Wolff:
> David Nolden, 01.03.2010:
> > Am Montag 01 März 2010 16:01:56 schrieb Milian Wolff:
> > > Hey all, esp. David!
> > >
> > > Is there any reason why an AbstractFunctionDeclaration does not inherit
> > >
> > >  from Declaration? And why is a ClassFunctionDeclaration only an
> > >
> > > AbstractFunctionDeclaration, but not a normal FunctionDeclaration?
> > >
> > > I find that rather unintuitive and makes my code harder since I cannot
> > > use simple polymorphie to handle methods and functions (in my case no
> > >
> > >  difference) in one go...
> > >
> > > Anything against me changing that?
> >
> > This cannot be changed, due to multiple inheritance.
> >
> > A ClassFunctionDeclaration inherits ClassMemberDeclaration as well as
> > AbstractFunctionDeclaration, and a FunctionDeclaration inherits
> > Declaration and AbstractFunctionDeclaration.
> >
> > "Declaration" must be only once in the whole inheritance chain, and for
> > that reason AbstractFunctionDeclaration is a pure abstract class that is
> > just "added" to FunctionDeclaration and ClassFunctionDeclaration. The
> > only other option would be making ClassMemberDeclaration such an abstract
> > class, but that would be a rather useless change.
> 
> So there is no useful connection whatsoever between a FunctionDeclaration
>  and ClassFunctionDeclaration - except for AbstractFunctionDeclaration
>  (typesafe but useless data) or Declaration (not typesafe yet the info I
>  need).
> 
> Or should I only pass pointers to AbstractFunctionDeclarations around and
>  cast them to... well what - Declarations?

What do you mean by typesafe? You can pass around pointers any way you like, 
and you can always do a 
dynamic_cast<AbstractFunctionDeclaration*>(yourDeclaration) or 
dynamic_cast<Declaration*>(yourAbstractFunctionDeclaration) to get from one 
class to the other.





More information about the KDevelop-devel mailing list