473,387 Members | 1,465 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,387 software developers and data experts.

?: operator compared to if-else

GS
Can somebody explain why first part works and second part does not? Second operator throws error below

Error 52 Type of conditional expression cannot be determined because there is no implicit conversion between '<null>' and 'double'
if (myItem.BuyItNowPrice == null)
{
myRow["Buy It Now Price"] = null;
}
else
{
myRow["Buy It Now Price"] = myItem.BuyItNowPrice.Value;
}

myRow["Buy It Now Price"] = (myItem.BuyItNowPrice == null) ? null : myItem.BuyItNowPrice.Value; <-- Does not work

Jan 10 '06 #1
2 1178
The conditional expression you used needs to work with equivalent data
types, types that are either the same data type, or can be implicitly
converted to the same data type.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"GS" <no****@nowhere.com> wrote in message
news:O%****************@TK2MSFTNGP09.phx.gbl...
Can somebody explain why first part works and second part does not? Second
operator throws error below

Error 52 Type of conditional expression cannot be determined because there
is no implicit conversion between '<null>' and 'double'
if (myItem.BuyItNowPrice == null)
{
myRow["Buy It Now Price"] = null;
}
else
{
myRow["Buy It Now Price"] = myItem.BuyItNowPrice.Value;
}

myRow["Buy It Now Price"] = (myItem.BuyItNowPrice == null) ? null :
myItem.BuyItNowPrice.Value; <-- Does not work
Jan 10 '06 #2
it has to do with the internal implementation of the operator. Your two statements are functionality equivilant, but that isn't actually what happens.

A local variable is created, to store the actual result. But since your result can be of two types it gets tripped up.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"GS" <no****@nowhere.com> wrote in message news:O%****************@TK2MSFTNGP09.phx.gbl...
Can somebody explain why first part works and second part does not? Second operator throws error below

Error 52 Type of conditional expression cannot be determined because there is no implicit conversion between '<null>' and 'double'
if (myItem.BuyItNowPrice == null)
{
myRow["Buy It Now Price"] = null;
}
else
{
myRow["Buy It Now Price"] = myItem.BuyItNowPrice.Value;
}

myRow["Buy It Now Price"] = (myItem.BuyItNowPrice == null) ? null : myItem.BuyItNowPrice.Value; <-- Does not work

Jan 10 '06 #3

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

Similar topics

2
by: psane | last post by:
I have the following code #include <iostream> #include <string> using namespace std; class superclass { public: superclass () {}
5
by: Bob Hairgrove | last post by:
Consider the following: #include <string> class A { public: A( const std::string & full_name , const std::string & display_name) : m_full_name(full_name)
7
by: Mikhail N. Kupchik | last post by:
Hi All. I have a question regarding Herb Sutter's idiom of implementation of operator= via nonthrowing swap() member function, to guarantee strict exception safety. The idea of the idiom is...
9
by: SpoonfulofTactic | last post by:
I am working on a new library for my own use that would allow me to use SI Units and to convert them back and forth with ease. However, While I have been working on operator overloading, I have...
17
by: Martin | last post by:
Below is some sample code to illustrate two warnings I get using a Hitachi compiler. When I use the GCC compiler I get a clean compile. I'd be grateful if someone could explain what the warnings...
34
by: Chris | last post by:
Is there ever a reason to declare this as if(*this == rhs) as opposed to what I normally see if(this == &rhs) ?
5
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
3
by: Demoris | last post by:
I have a class that I believe should work. I've compared it to previous programs I've written, compared it to examples from my professor, to examples in my textbook, but can't see why I get the...
12
by: dimstthomas | last post by:
I have a class that already has == and != operators that I want to use in a map that uses my class (not a pointer to the class) as the key. To do this I need a < operator. Is this a valid less than...
19
by: C++Liliput | last post by:
I have a custom String class that contains an embedded char* member. The copy constructor, assignment operator etc. are all correctly defined. I need to create a map of my string (say a class...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.