typecasting ???

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...
 
C

Carl Daniel [VC++ MVP]

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
 
C

cmrchs

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top