|
-
October 15th, 2014, 12:53 PM
#1
Implicit Conversion Operators and Value Types
Folks,
I’ve come across this blog article: Implicit Conversion Operators are Bad. The article discourages the use of implicit conversion with reference types. In the beginning, the article has got this statement:
Implicit conversion operators are incredibly important to the language, but only for value types. [emphasis original]
Then the article goes on to describe problems caused by implicit conversions of reference types (which I understand, I think). The article doesn’t explain how to use implicit conversion with value types. This is what I’m wondering about. My present thinking is this:
- The conversion operator is on a value type, and it returns a value type. Implicit - okay.
- The conversion operator is on a reference type, and it returns a value type. Implicit – okay.
- The conversion operator is on a value type, and it returns a reference type. (That would be a somewhat bizarre, but would it be wrong?) Implicit – not okay.
- The conversion operator is on a reference type, and it returns a reference type. Implicit – not okay.
If it returns a value type, an implicit conversion operator is okay on both value type and reference type.
If it retirns a reference type, implicit conversion is not okay.
Is this correct? Is this complete?
Any suggestion, insight or reference is really appreciated!
Cheers,
- Nick
P.S. For the most part, I work mostly with C and C++, where I have fine control over things like const, pointers, references. Of course, that comes at a risk of having nasty pointer-related bugs.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|