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
4 answers

implicit conversion in literals

By default, Java assumes you are defining an int value with a literal. short x = 20; // There is an implicit conversion But when we use "x" variable in an arithmetic expression, for eample: short y = x * 2; //DOES NOT COMPILE We know the result of…
Luisk4
  • 377
  • 1
  • 5
  • 12
1
vote
3 answers

Is it possible to join two tables on a column that contains a mix of castable and uncastable data?

Apologies if this has been asked before, I combed through a lot of questions but wasn't able to find an answer I could apply to this problem. I'm putting together an SSRS report from a database I have read-only access to and am having trouble…
Jared
  • 25
  • 3
1
vote
1 answer

define implicit conversion from template class to primitive type based on other template

I have a class defined by two templates. template my_class { private: A value; public: operator A () { return this->value; } }; I want to define an implicit conversion between the class and the first…
mbtg
  • 95
  • 1
  • 8
1
vote
2 answers

Conversion to tuple with by-name parameter

I would like to create a function with the following signature: def myFunction[T](functionWithName: (String, => T)): T so that I can call it, e.g., like this: val x = myFunction("abc" -> 4 * 3). Tuple doesn't accept by-name parameter, however, so…
Mifeet
  • 12,949
  • 5
  • 60
  • 108
1
vote
2 answers

Is this loop implicitly casting an int to size_t?

I ran into a bug in my program: for (int i = 0; i < objArray.size() - 1; ++i) In my case objArray.size() is an unsigned long long and an empty vector minus 1 equals about 18 quintillion. I was wondering, does the loop on every iteration have to…
Zebrafish
  • 11,682
  • 3
  • 43
  • 119
1
vote
1 answer

C++11 basic_istream conversion to bool

From what I've read, C++11 no longer supports an implicit conversion to void* for istream/ostream, which could then be implicitly converted to bool, for use in while loops etc. For example: string test; while((getline(cin,test))) { …
1
vote
2 answers

Why is this user-defined conversion not done?

Consider: template struct Prop { T value; operator T() { return value; } }; int main() { Prop p1 { 5 }; Prop> p2 { { 1, 2, 3 } }; float f1 = p1; // Works fine float f2_1_1…
Roel
  • 19,338
  • 6
  • 61
  • 90
1
vote
2 answers

Conversion of function parameter from signed int to unsigned int

In the following code snippet that I stumbled upon the other day which passes a signed int to a function that expects an unsigned int #include "stdio.h" void set_data(unsigned int* addr, const unsigned int data) { printf("Inside…
Zakir
  • 2,222
  • 21
  • 31
1
vote
1 answer

Explicit and implicit conversion

I am pretty surprised that this struct, which is only explicitly convertible to bool, works fine inside a if statement: struct A { explicit operator bool( ) const { return m_i % 2 == 0; } int m_i; }; int main() { A a{…
1
vote
1 answer

Casting a Map[String,String] to a case class User(id, name) using implicit method

I've seen examples of how to do the conversion of a Map[String,String] such as ("id"->"1", "name"->"andre") to a case class User(id:String,name:String), but they involve calling a method mapToUser - for example: val r = User.mapToUser(u.get) …
Fernando André
  • 1,213
  • 3
  • 19
  • 32
1
vote
1 answer

Implicit operator overloading with boost::variant C++

Can anyone guide me on how to solve this problem. I have a boost::variant. typedef boost::variant < int, std::string, bool, double, vector, vector, vector, vector > boostVar; I am trying to create overload [] operator as…
1
vote
1 answer

Implicit type conversion to array

I'll just get right down to it: Why doesn't line 38 implicitly convert to char (&)[32]? template struct StringT { private: char mChars[StringSize]; public: // Note: CharArray can decay to char*. typedef char…
1
vote
0 answers

A Large Number of Similar Functions

There are two databases, Db_A and Db_B, each with their own data dictionary. Most of the data in my database, Db_A, will fit in some field or another of the target database Db_B. Many values from Db_A will require reformatting before being inserted…
1
vote
0 answers

using NLTK "Can't convert 'list' object to str implicitly"

I am writing a code that opens a link and collects words surrounding a substring j into Res, and then collects all the nouns in Res as follows: j="Green Index" #defining word to be looked for sub = '(\w*)\W*(\w*)\W*(%s)\W*(\w*)\W*(\w*)' % j…
El_1988
  • 339
  • 3
  • 13
1
vote
1 answer

Implicit conversion not applying

I was trying to workout the classic example of converting arbitrary values into their Json representation and having compile time errors in case conversion is not defined. So far, I have, trait Json trait ConvertableToJson[A] { def toJson:…
Dhruv Kapur
  • 726
  • 1
  • 8
  • 24
1 2 3
99
100