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 Linda Derezinski <li...@interfacecontrol.com> on 2000/05/10 04:35:50 UTC
C++ style casting (Was RE: converting DOM_Node to DOM_Element)
Not to completely beat this subject into the ground ...
But what is the difference between the following?
DOM_Element el = dynamic_cast<DOM_Element &>(some_DOM_Node);
DOM_Element el = reinterpret_cast<DOM_Element &>(some_DOM_Node);
DOM_Element el = static_cast<DOM_Element &>(some_DOM_Node);
I thought the dymamic_cast<> would at runtime verify that some_DOM_Node
really had DOM_Element somewhere in it's hierarchy.
I thought static_cast< DOM_Element &> was exactly like the c-style cast
(DOM_Element)
-Linda Derezinski
-----Original Message-----
From: Andy Heninger [mailto:andyh@jtcsv.com]
Sent: Tuesday, May 09, 2000 8:57 PM
To: xerces-c-dev@xml.apache.org
Subject: Re: converting DOM_Node to DOM_Element
<snip/>
As Dave Bertoni noted, code of the general form
DOM_Element el = static_cast<DOM_Element &>(some_DOM_Node);
is the way to go when a down-cast is required.
Andy Heninger
IBM XML Technology Group, Cupertino, CA
heninger@us.ibm.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
RE: C++ style casting (Was RE: converting DOM_Node to DOM_Element)
Posted by Ward Cannon <wa...@creativeplanet.com>.
<static_cast> - generally turns off type checking during assignment
operations
an example...
double d = 97.0;
char ch = static_cast<char>(d); //assignment from a larger type to a
smaller type
In Visual C++ 6.0 you wont get a warning message here.
<reinterpret_cast> - explicit pointer cast in C++
an example...
complex<double> *pcom; //a pointer to something unusual..
char *pc = reinterpret_cast<char*>(pcom) // pcom is not really a char*
string str(pc); //potential run-time error
<dynamic_cast> - allows you make assignments up and down an inherited class
hierchy. an example is where dayTimeEmployee is inherited from Employee.
company::dayTimePayRoll(*Employee emp)
{
dayTimeEmployee *dEmp = dynamic_cast< Employee*>(emp);
}
May I recommend Stanley Lippmanns most excellent book C++ Primer Third
Edition?
He gives a good treatment on why you would and would not want to use them.
Regards,
Ward
-----Original Message-----
From: Linda Derezinski [mailto:linda@interfacecontrol.com]
Sent: Tuesday, May 09, 2000 7:36 PM
To: xerces-c-dev@xml.apache.org
Subject: C++ style casting (Was RE: converting DOM_Node to DOM_Element)
Not to completely beat this subject into the ground ...
But what is the difference between the following?
DOM_Element el = dynamic_cast<DOM_Element &>(some_DOM_Node);
DOM_Element el = reinterpret_cast<DOM_Element &>(some_DOM_Node);
DOM_Element el = static_cast<DOM_Element &>(some_DOM_Node);
I thought the dymamic_cast<> would at runtime verify that some_DOM_Node
really had DOM_Element somewhere in it's hierarchy.
I thought static_cast< DOM_Element &> was exactly like the c-style cast
(DOM_Element)
-Linda Derezinski
-----Original Message-----
From: Andy Heninger [mailto:andyh@jtcsv.com]
Sent: Tuesday, May 09, 2000 8:57 PM
To: xerces-c-dev@xml.apache.org
Subject: Re: converting DOM_Node to DOM_Element
<snip/>
As Dave Bertoni noted, code of the general form
DOM_Element el = static_cast<DOM_Element &>(some_DOM_Node);
is the way to go when a down-cast is required.
Andy Heninger
IBM XML Technology Group, Cupertino, CA
heninger@us.ibm.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