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

Milian Wolff mail at milianw.de
Mon Mar 1 20:06:35 UTC 2010


On Monday 01 March 2010 19:20:18 David Nolden wrote:
> 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.

With typesafe I mean something like:

void extractInformation(Declaration* dec);

VS

void extractInformation(FunctionDeclaration* dec);

So if you say that the two dynamic casts work, I have to try out the latter. I 
thought this is not possible as they have no direct connection whatsoever.


-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20100301/f60ff0d2/attachment.sig>


More information about the KDevelop-devel mailing list