You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Ryan Koss <rk...@acmepacket.com> on 2001/04/02 21:35:45 UTC

Re: Casting DOM_Node to DOM_Element... still a problem.

What compiler and OS is this running on because I still get a the following
compiler error when I try to do the cast that has been stated in this
multi-threaded email...  I am running Mandrake linux 7.1 and my compiler is
GCC 2.95.3

xmlobject.cpp:446: conversion to non-const reference type `class DOM_Element
&'
xmlobject.cpp:446: from rvalue of type `DOM_Node'
make: *** [xmlobject.o] Error 1

Here is the code, I am cycling through a list of DOM_Nodes here...

 DOM_Element elem = static_cast<DOM_Element&>(nodeList.item(i));

Any help, ideas, notion, guesses would be greatly appreciated.  Thanks in
advance
-ryan

----- Original Message -----
From: "Miroslaw Dobrzanski-Neumann" <mn...@mosaic-ag.com>
To: <xe...@xml.apache.org>
Sent: Friday, March 23, 2001 11:45 AM
Subject: Re: Casting DOM_Node to DOM_Element


> On Fri, Mar 23, 2001 at 09:20:22AM -0500, David E. Cleary wrote:
> >
> >
> > > -----Original Message-----
> > > From: jpcs@progress.com [mailto:jpcs@progress.com]On Behalf Of John
> > > Snelson
> > >
> > > The C++ way of doing this is the following code fragment:
> > >
> > > if(node.getNodeType() == DOM_Node::ELEMENT_NODE) {
> > >   DOM_Element element = static_cast<DOM_Element&>(node);
> > > }
> >
> > Wouldn't dynanic_cast be more what Curt is looking to do, as that will
> > actually perform a runtime check to see in node is indeed a DOM_Element?
> > I've never used these casting constructs myself, so I am interested in
> > hearing other's thoughts on them.
>
> The cleanest way to do casting is using class specific cast operator or
cast
> constructor.
> element = (DOM_Element) node
> is clean (???) cast in Java but it does not work in C++.
> element = static_cast<DOM_Element&>(node);
> says "I do know what I do" (what about the future?)
>
>
> The solution 1 (cast operator):
> class DOM_Node
> {
> ...
> operator DOM_Element(void);
> };
>
> The solution 2 (cast constructor):
> class DOM_Element
> {
> ...
> DOM_Element (const DOM_Node&);
> };
>
> Both solution are better then direct cast because the casts are method
calls
> which can do what they want to guarantee the correct casting. For invalid
> conversion one could throw a appropriate exception. I (and many others as
I
> guess) would wellcome one of them in Xerces DOM.
>
> regards.
> --
> Miroslaw Dobrzanski-Neumann
>
> MOSAIC SOFTWARE AG
> Base Development and Research
> Tel +49-2225-882-291
> Fax +49-2225-882-201
> E-mail: mne@mosaic-ag.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Casting DOM_Node to DOM_Element... still a problem.

Posted by Ryan Koss <rk...@acmepacket.com>.
Thanks Andy, that was what I was missing...

-ryan

----- Original Message -----
From: "Andy Heninger" <an...@jtcsv.com>
To: <xe...@xml.apache.org>
Sent: Monday, April 02, 2001 4:57 PM
Subject: Re: Casting DOM_Node to DOM_Element... still a problem.


> >  DOM_Element elem = static_cast<DOM_Element&>(nodeList.item(i));
>
>
> nodeList.item() is returning a DOM_Node by value.  The value
> that you are trying to cast doesn't have a usable memory
> address at that point - it's just a temporary value in the
> middle of an expression - so casting it to a reference type
> doesn't work.  This is what the "from rvalue of ..." in the
> error message means.
>
> Adding an intermediate variable should fix the problem
>
> DOM_Node t = nodList.item(i);
> DOM_Element elem = static_cast<DOM_Element &>t;
>
> Andy Heninger
> IBM, Cupertino, CA
> heninger@us.ibm.com
>
>
>
> ----- Original Message -----
> From: "Ryan Koss" <rk...@acmepacket.com>
> To: <xe...@xml.apache.org>
> Sent: Monday, April 02, 2001 12:35 PM
> Subject: Re: Casting DOM_Node to DOM_Element... still a problem.
>
>
> > What compiler and OS is this running on because I still get a the
> following
> > compiler error when I try to do the cast that has been stated in this
> > multi-threaded email...  I am running Mandrake linux 7.1 and my compiler
> is
> > GCC 2.95.3
> >
> > xmlobject.cpp:446: conversion to non-const reference type `class
> DOM_Element
> > &'
> > xmlobject.cpp:446: from rvalue of type `DOM_Node'
> > make: *** [xmlobject.o] Error 1
> >
> > Here is the code, I am cycling through a list of DOM_Nodes here...
> >
> >  DOM_Element elem = static_cast<DOM_Element&>(nodeList.item(i));
> >
> > Any help, ideas, notion, guesses would be greatly appreciated.  Thanks
> in
> > advance
> > -ryan
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Casting DOM_Node to DOM_Element... still a problem.

Posted by Andy Heninger <an...@jtcsv.com>.
>  DOM_Element elem = static_cast<DOM_Element&>(nodeList.item(i));


nodeList.item() is returning a DOM_Node by value.  The value
that you are trying to cast doesn't have a usable memory
address at that point - it's just a temporary value in the
middle of an expression - so casting it to a reference type
doesn't work.  This is what the "from rvalue of ..." in the
error message means.

Adding an intermediate variable should fix the problem

DOM_Node t = nodList.item(i);
DOM_Element elem = static_cast<DOM_Element &>t;

Andy Heninger
IBM, Cupertino, CA
heninger@us.ibm.com



----- Original Message -----
From: "Ryan Koss" <rk...@acmepacket.com>
To: <xe...@xml.apache.org>
Sent: Monday, April 02, 2001 12:35 PM
Subject: Re: Casting DOM_Node to DOM_Element... still a problem.


> What compiler and OS is this running on because I still get a the
following
> compiler error when I try to do the cast that has been stated in this
> multi-threaded email...  I am running Mandrake linux 7.1 and my compiler
is
> GCC 2.95.3
>
> xmlobject.cpp:446: conversion to non-const reference type `class
DOM_Element
> &'
> xmlobject.cpp:446: from rvalue of type `DOM_Node'
> make: *** [xmlobject.o] Error 1
>
> Here is the code, I am cycling through a list of DOM_Nodes here...
>
>  DOM_Element elem = static_cast<DOM_Element&>(nodeList.item(i));
>
> Any help, ideas, notion, guesses would be greatly appreciated.  Thanks
in
> advance
> -ryan
>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org