This is a multi-part message in MIME format.
------=_NextPart_000_00AC_01C57B33.B9275B80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I have 2 question:
1. testing type:
in C#, to test the type of an object I could write, for exemple
object o;
//....
if(o is string)
{
// do something
}
how do I do that in Managed C++?
so far I write
if( dynamic_cast<String^>( o ) )
{
// do something
}
but I found this somewhat unelegant...
2. calling the super type!
I overwrite a class. I want to call the parent method:
ref class MyClass : SuperClass
{
public:
virtual property Object^ Target
{
void set(Object^ o) override
{
id^ _id =3D dynamic_cast<id^>( o );
if( !_id )
throw gcnew ArgumentException();
__super::Target =3D o;
}
}
};
it doesn't compile ?!?! I don't know what to write ....
------=_NextPart_000_00AC_01C57B33.B9275B80
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2668" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>I have 2 question:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>1. testing type:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>in C#, to test the type of an object I =
could write,=20
for exemple</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>object o;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>//....</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>if(o is string)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> // do =
something</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>how do I do that in Managed =
C++?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>so far I write</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>if( dynamic_cast<String^>( o ) =
)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> // do =
something</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>but I found this somewhat =
unelegant...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>2. calling the super type!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I overwrite a class. I want to call the =
parent=20
method:</FONT></DIV>
<DIV><FONT color=3D#0000ff size=3D2>ref</FONT><FONT size=3D2> =
</FONT><FONT=20
color=3D#0000ff size=3D2>class</FONT><FONT size=3D2> MyClass :=20
SuperClass</FONT></DIV>
<DIV><FONT size=3D2>{</FONT></DIV>
<DIV><FONT color=3D#0000ff size=3D2>public</FONT><FONT =
size=3D2>:</FONT></DIV>
<DIV><FONT color=3D#0000ff size=3D2> =
virtual</FONT><FONT size=3D2>=20
</FONT><FONT color=3D#0000ff size=3D2>property</FONT><FONT size=3D2> =
Object^=20
Target</FONT></DIV>
<DIV><FONT size=3D2> {</FONT></DIV>
<DIV><FONT color=3D#0000ff size=3D2> =
=20
void</FONT><FONT size=3D2> set(Object^ o) </FONT><FONT color=3D#0000ff=20
size=3D2>override</FONT></DIV>
<DIV><FONT size=3D2> {</FONT></DIV>
<DIV><FONT size=3D2> =
id^=20
_id =3D </FONT><FONT color=3D#0000ff size=3D2>dynamic_cast</FONT><FONT=20
size=3D2><id^>( o );</FONT></DIV>
<DIV><FONT color=3D#0000ff size=3D2> =
=20
if</FONT><FONT size=3D2>( !_id )</FONT></DIV>
<DIV><FONT color=3D#0000ff size=3D2> =
=20
throw</FONT><FONT size=3D2> =
</FONT><FONT=20
color=3D#0000ff size=3D2>gcnew</FONT><FONT size=3D2> =
ArgumentException();</FONT></DIV>
<DIV><FONT=20
size=3D2> &nbs=
p;=20
__super::Target =3D o;</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV>
<DIV><FONT size=3D2>};</DIV></FONT>
<DIV>
<P><FONT face=3DArial size=3D2></FONT><FONT face=3DArial size=3D2>it =
doesn't compile=20
?!?! I don't know what to write ....</FONT></P></DIV></BODY></HTML>
------=_NextPart_000_00AC_01C57B33.B9275B80--