typecasting ???

  • Thread starter Thread starter cmrchs
  • Start date Start date
C

cmrchs

Hi,

what is the way to check whether a value is truly a boolean :

I try the following:

Object ^obj = m_XPathNav->Evaluate(<some xpath expression>);

if (nullptr != static_cast<double^>(obj) )
sMessage = "double";
else if (nullptr != static_cast<bool^>(obj) )
sMessage = "boolean";

Even with boolean values does the first typecast always return true so I always get "double"

In C# there exist the is-operator that clearly makes a distinction.
Is there a C++ - version of the is-operator ?

thanks
Chris

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
Chris said:
Hi,

what is the way to check whether a value is truly a boolean :

I try the following:

Object ^obj = m_XPathNav->Evaluate(<some xpath expression>);

if (nullptr != static_cast<double^>(obj) )
sMessage = "double";
else if (nullptr != static_cast<bool^>(obj) )
sMessage = "boolean";

Even with boolean values does the first typecast always return true
so I always get "double"

In C# there exist the is-operator that clearly makes a distinction.
Is there a C++ - version of the is-operator ?

Here's a small sample:

#using <mscorlib.dll>

using namespace System;

void test(String^ name, Object^ obj)
{
Console::Write("{0}: ",name);
if (obj->GetType() == Boolean::typeid)
Console::WriteLine("Yes");
else
Console::WriteLine("No");
}

int main()
{
test("double",1.0);
test("bool",true);
test("int",5);
}

-cd
 
thanks, I'll try that !

using dynamic_cast<> works as well of course (= standard C++)

greetz
Chris

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
Back
Top