473,382 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

typecasting ???

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...
Nov 17 '05 #1
4 1092
Chris C wrote:
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
Nov 17 '05 #2
Chris C wrote:
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
Nov 17 '05 #3
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...
Nov 17 '05 #4
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...
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kapil Khosla | last post by:
Hi, I have been trying to understand this concept for quite sometime now somehow I am missing some vital point. I am new to Object Oriented Programming so maybe thats the reason. I want to...
7
by: Nicolay Korslund | last post by:
Hi! I'm having a little trouble with the typecast operator, can anybody help me with the rules for when the this operator is invoked? In the class 'Test' in the code below, the typecast operator...
2
by: Arun Prasath | last post by:
Hi all, I have the following question regd pointer typecasting. Is the following type of pointer typecasting valid? #define ALLOC(type,num) ((type *)malloc(sizeof(type)*num)) /*begin...
63
by: andynaik | last post by:
Hi, Whenever we type in this code int main() { printf("%f",10); } we get an error. We can remove that by using #pragma directive t direct that to the 8087. Even after that the output is...
11
by: Vinod Patel | last post by:
I have a piece of code : - void *data; ...... /* data initialized */ ...... struct known_struct *var = (struct known_struct*) data; /*typecasting*/ How is this different from simple...
3
by: jdm | last post by:
In the sample code for the SortedList class, I see the use of a string typecasting macro consisting of a single letter "S". i.e.: Sortedlist->Add(S"Keyval one", S"Item one"); Now I have...
7
by: Raghu | last post by:
Hello All, I need some help regarding overloading operation. Is there any way to overload typecasting? I mean if i have a piece of code as below. int a = 2: float b; b = (float)a;
16
by: Abhishek | last post by:
why do I see that in most C programs, pointers in functions are accepted as: int func(int i,(void *)p) where p is a pointer or an address which is passed from the place where it is called. what...
4
by: vivekian | last post by:
Hi, This is the part of the code am trying to compile to : void Server::respondToClient ( std::string response ) { .... .... if ((numbytes = sendto ( sockFd_ , response , sizeof(response)...
12
by: bwaichu | last post by:
What is the best way to handle this warning: warning: cast from pointer to integer of different size I am casting in and out of a function that requires a pointer type. I am casting an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.