Questions tagged [implicit-conversion]

Converting an object, variable or value from one type to another to satisfy a type restriction, without specifically requesting that conversion through language syntax.

Converting an object, variable or value from one type to another to satisfy a type restriction, without specifically requesting that conversion through language syntax.

Implicit conversion is a subset of .

2401 questions
1
vote
2 answers

C++ double pointer array to float conversion

What is a correct way to convert double to float in c++. Is the conversion implicit? Question 1: Consider double d = 5.0; and float f; Which one is correct? f = d; f = (float)d; f = static_cast(d); Question 2: Now consider we have char…
mohsen_og
  • 774
  • 1
  • 9
  • 31
1
vote
1 answer

C++ Compiler Reports Ambiguous Function Call When Using Bool Wrapper Class

I have a delima. I'm using wrapper classes for native types, however, when using the wrapper types as function arguments, the implicit conversion for char pointer to bool keeps causing the compiler to issue an ambiguous function call error: class…
SirKM
  • 60
  • 5
1
vote
1 answer

Scala chaining implicits conversions for Option[T]

I try to make implicit conversions chain that from Symbol -> A -> Option[A]. But fail to make it working with generic Option conversion, for example: implicit def toInt(n: Symbol): Int = n.toString.length implicit def symbolToString(n: Symbol):…
D. Kuzniatsou
  • 23
  • 1
  • 4
1
vote
1 answer

Scala - Acessing the type of a parameterized class

Imagine I have a Box that can hold animals of some type. This Box can be given raw data which should be transformed/serialized into an animal of the same type of those already in the Box. In other words, if a Box of dogs is given some "data", I want…
cmhteixeira
  • 877
  • 11
  • 22
1
vote
1 answer

Scala unexpected output for List.orElse

I expect the following code output with Seq(0), instead it returns a function ? @ Seq(0).orElse(Seq(1)) res2: PartialFunction[Int, Int] = I suspected at first that via syntax sugar it orElse on apply function, but it didn't since by…
WeiChing 林煒清
  • 4,452
  • 3
  • 30
  • 65
1
vote
0 answers

Imcplicit conversion from string literal to unsigned int (bool)

When I run the below test program, I would have expected that the string literal matches the std::string constructor, instead the bool version is called. I wonder how this is covered in the standard and I sure don't understand why this is converted…
Devolus
  • 21,661
  • 13
  • 66
  • 113
1
vote
2 answers

Confusion about return and parameter types

I'm really new to c++ and have just been experimenting around with some code and there's something I don't really seem to get: #include using namespace std; int f (const long& i) { return i+1; } void g (long& i) { f…
1
vote
1 answer

var array = new [] {d, "hello"} is implicitly typed to dynamic[] and not string[] ? why?

dynamic d = 5; var array = new[] {d,"hello"} What is the implicit type of array ? It is dynamic[] but not string[], why ? While going through C# in depth - Jon Skeet stated a rules for dynamic conversions : An implicit conversion exists from any…
rahulaga-msft
  • 3,964
  • 6
  • 26
  • 44
1
vote
1 answer

DataFrame user-defined function not applied unless I change column name

I want to convert my DataFrame column using implicits functions definition. I have my DataFrame type defined, which contains additional functions: class MyDF(df: DataFrame) { def bytes2String(colName: String): DataFrame = df …
belka
  • 1,480
  • 1
  • 18
  • 31
1
vote
0 answers

C# implicit/explicit cast to generic type for type generic class

I have a class like the following for holding multiple objects. At the Moment it is Possible to get Objects with .Get(). I want to be able to get the objects by casting the MultiHolder<...> MultiHolder multiHolder =…
AntiHeadshot
  • 1,130
  • 9
  • 24
1
vote
1 answer

Continuations and implicit conversions

I was experimenting with continuations, and I came across a case that seems to suggest that @cpsParam thwarts implicit conversions. I have def v: T @cpsParam[Unit, Unit] // ...and then later v must_== 42 // where must_== is from specs/mockito I get…
Topher
  • 76
  • 6
1
vote
2 answers

Generic Point Addition in Scala

I'm trying to pimp the Tuple(2) class with addition and scala multiplication members, so that I can use them more easily as geometric 2D points. This is what I've got: implicit class Point[+T: Numeric](val t: (T, T)) { import Numeric.Implicits._ …
linkhyrule5
  • 871
  • 13
  • 29
1
vote
2 answers

C++: Using function overloading with implicit conversion between char to int or vice versa

In C++, if char to int is implicit conversion and int to char is also implicit conversion. Normally, a char is single or double byte. On 32-bit machine an int is usually 4-byte. Thus, int to char conversion has the possibility of data loss (as…
Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
1
vote
1 answer

Scala implicit class nested type parameter

I have implicit classes with nested type parameters to provide relevant methods to the data-object only when certain conditions are met and to store type information for later use. Somehow a nested type parameter only works with a wildcard but not…
user3508638
  • 195
  • 1
  • 7
1
vote
2 answers

SSIS Data flow task implicit conversion automatically

I have following scenario: I have one data flow task with OLEDB source, taking data from source tables using query with inner join. One of the column is varchar(8) and few values are float, rest are int into this column. The OLEDB destination is…