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

Problem with implicit conversions and higher-order apply methods in Scala

I am trying to extend String with a new apply method that lets me apply an higher-order function on it. Example: case class A(s:String, f: List[String] => List[String]) val f: List[String] => List[String] = { ... stuff ... } "foo"{f} // == A("foo",…
1
vote
2 answers

do variables automatically convert to the type required by the function as the appropriate arguments?

do variables automatically convert to the type required by the function as the appropriate arguments? #include void swap(int &i, int &j) { //the arguments here are int& int temp = i; i = j; j = temp; } int main(void) { int a =…
1
vote
1 answer

Make use of implicit conversion operator inside expression tree

Suppose I have the following type with an implicit convertion operator: public readonly struct WrappedInt { public WrappedInt(int value) { Value = value; } public int Value { get; } public static implicit operator int…
Yuriy Ivaskevych
  • 956
  • 8
  • 18
1
vote
1 answer

Implicit conversion from uint8_t to int gone wrong, when explicit one gone well

I've got a program, which gets numbers n(quantity of blocks) and r(volume), and after it gets n sizes in format firstsize secondsize thirdsize (e.g. 1 1 1) so the overall simplest input is: 1 1 1 1 1 which in theory should return 1. But it…
1
vote
1 answer

Ambiguous concept of conversion in Java

I really find the concept of conversion to be confusing. short a = 34; short b = (short)34; What is the linguistic difference between these two statements? I think that, in the first statement the int literal 34 is directly stored in the short…
user12208242
  • 315
  • 1
  • 11
1
vote
1 answer

Scala: why type conversion implicit breaks the code

I have a simple code private def convertFieldsNames (fieldsNames: Array[String]): Array[String] = fieldsNames.map(convertFieldName) private def convertFieldName (fieldName: String): String = s"!!! $fieldName" val res =…
Dmitry Reutov
  • 2,995
  • 1
  • 5
  • 20
1
vote
2 answers

Implicit casting limitations

I am trying to support implicit casts of literal values in a type system. These implicit casts are intended and ideal (See note 1). I'm aware that C++ can perform multiple implicit casts in an expression. The second line of main below does not…
ktb
  • 1,498
  • 10
  • 27
1
vote
1 answer

Cannot convert const object in Return

I'm not entirely sure what I'm doing incorrectly here. I have a class which contains a constant pointer to another class object. However I'm getting an error about not being able to convert the const (class object). What am I doing wrong? Is my code…
JokerMartini
  • 5,674
  • 9
  • 83
  • 193
1
vote
1 answer

error: cannot convert 'const char**' to 'const char (*)[64]'

I try to implement source code as below: bool getParam(char* cmd, char** prm_arr, int num) { } void main() { char strC[] = "btOK,btCancel"; char foo[10][10]; bool res = getParam(strC,foo,2); } It shows error: error: cannot convert…
ThomasD
  • 23
  • 5
1
vote
2 answers

c++ no suitable conversion function from "std::string" to "const char*" exists

the question as the title suggests, is an error when i was executing my program in the certain part of the password function. actually it is a basic password function which was working properly in turbo c++, but in visual c++ this error arrives…
Shazin
  • 13
  • 4
1
vote
1 answer

Temporary materialization conversion not in a standard conversion sequence

Temporary materialization conversion is a standard conversion, see § 7.3 Standard Conversions; 7.3.4 [conv.rval]: A prvalue of type T can be converted to an xvalue of type T. This conversion initializes a temporary object ([class.temporary]) of…
Krystian S
  • 1,586
  • 7
  • 23
1
vote
2 answers

C++ ifstream::read confusion

I would like to iterate through the bytes of a file stream. I am using ifstream class. When you use the read function, it copies characters from the stream into the array that I specify in the argument list. I have 3 questions. int length =…
Patrik Nusszer
  • 460
  • 3
  • 13
1
vote
2 answers

getting Suspicious application of an implicit view when converting from Option(lang.Long) to Long

after adding this flag to scalacoptions : "-Xlint:option-implicit" I don't understand why am I getting this and how to resolve it Error:(47, 34) Suspicious application of an implicit view (scala.Predef.Long2long) in the argument to…
igx
  • 4,101
  • 11
  • 43
  • 88
1
vote
1 answer

Implicit downcast of shared_ptr in CRTP

I built a class Interface to be used with CRTP for static polymorphism and a Client class having a shared_ptr to the Interface. I would like to return from the Client the shared_ptr to the Implementation, something that I can (safely?) do through…
Teloze
  • 279
  • 2
  • 8
1
vote
1 answer

prevent string literals from being converted to bool versus std::string

Similar questions have been asked before, such as String literal matches bool overload instead of std::string. But what I want to know is what should C++ developers do to prevent this from happening? As someone who writes C++ libraries for others…
Stéphane
  • 19,459
  • 24
  • 95
  • 136