N
nicolas.hilaire
Hi all,
i've read this article
http://msdn2.microsoft.com/en-us/library/85af44e9.aspx who first
interest me much.
I've translated it to use generic instead of template :
generic < typename T, typename U >
Boolean isinst(U u)
{
return safe_cast< T >(u) != nullptr;
}
but i realised that this can't be really a good solution. For example,
this example :
Collections::ArrayList^ a = gcnew Collections::ArrayList();
if ( isinst< Collections::ICollection ^ >(a) )
Console::WriteLine("a is a ICollection ");
We can understand that the safe_cast is working, so the function
returns true.
Before reading this article, I used to compare object with such a way :
if (a->GetType() == Collections::ICollection::typeid)
Console::WriteLine("a is a ICollection ");
In this example, the if statement is false, because a is not a
ICollection.
Can you explain me where i am wrong ? Or is the Msdn article incomplete
?
Thanks in advance for your answers,
Nico
i've read this article
http://msdn2.microsoft.com/en-us/library/85af44e9.aspx who first
interest me much.
I've translated it to use generic instead of template :
generic < typename T, typename U >
Boolean isinst(U u)
{
return safe_cast< T >(u) != nullptr;
}
but i realised that this can't be really a good solution. For example,
this example :
Collections::ArrayList^ a = gcnew Collections::ArrayList();
if ( isinst< Collections::ICollection ^ >(a) )
Console::WriteLine("a is a ICollection ");
We can understand that the safe_cast is working, so the function
returns true.
Before reading this article, I used to compare object with such a way :
if (a->GetType() == Collections::ICollection::typeid)
Console::WriteLine("a is a ICollection ");
In this example, the if statement is false, because a is not a
ICollection.
Can you explain me where i am wrong ? Or is the Msdn article incomplete
?
Thanks in advance for your answers,
Nico