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

Where does const char* get the pointer to a memory address?

This may be simple question, but why does a const char* not need a memory address to point to? Example: const char* a = "Anthony"; and not: const char *a = // Address to const char like any other types do?
Weidelix
  • 401
  • 3
  • 6
24
votes
5 answers

Incorrect assignment of values in char enum

I was playing with enums and tried to reproduce some examples from this page. Initial examples worked as intended, however I got some interesting results with following code: #include enum num : char { zero = '0', one = '1', …
Abhinav Gauniyal
  • 7,034
  • 7
  • 50
  • 93
24
votes
1 answer

no implicit conversion of nil into String error

I have a ruby script that will create two files by taking and merging values from another file. #Resources require 'rubygems' require 'csv' col_date = [] col_constant1 = [] col_constant2 = [] col_appYear = [] col_statsDesc = [] col_keyStats…
Angela Jonon
  • 253
  • 1
  • 2
  • 8
24
votes
4 answers

Why can I assign struct with a pointer?

Why does it even compile? struct UE{ UE(bool a = true) { }; // UE(){}; // if UE took no initial args and called below, gcc will complain. }; class VA { protected: UE ue; public: VA(); }; VA::VA() { ue = new…
BetterWang
  • 243
  • 1
  • 4
23
votes
5 answers

implicit operator

I just saw it was using in one of the recent answers: public static implicit operator bool(Savepoint sp) { return sp != null; } Why do we need word implicit here, and what does it mean?
Sasha
23
votes
3 answers

Understanding copy-initialisation and implicit conversions

I am having trouble understanding why the following copy-initialization doesn't compile: #include struct base{}; struct derived : base{}; struct test { test(std::unique_ptr){} }; int main() { auto pd =…
linuxfever
  • 3,763
  • 2
  • 19
  • 43
23
votes
4 answers

PHP Convert String into Float/Double

I have list of string (size in bytes), I read those from file. Let say one of the string is 2968789218, but when I convert it to float it become 2.00. This is my code so far : $string = "2968789218"; $float = (float)$string; //$float =…
Bias Tegaralaga
  • 2,240
  • 5
  • 21
  • 26
23
votes
3 answers

How to cast implicitly on a reflected method call

I have a class Thing that is implicitly castable from a string. When I call a method with a Thing parameter directly the cast from string to Thing is done correctly. However if I use reflection to call the same method it throws the…
Dio F
  • 2,458
  • 1
  • 22
  • 39
22
votes
4 answers

Implicit conversion issue in a ternary condition

Possible Duplicate: Conditional operator cannot cast implicitly? Why does null need an explicit type cast here? I've had a search and haven't found a good explanation for why the following occurs. I have two classes which have an interface in…
Andy Rose
  • 16,770
  • 7
  • 43
  • 49
22
votes
5 answers

Overload resolution failure when streaming object via implicit conversion to string

Disclaimer: I know that implicit conversion to string should be avoided, and that the proper approach would be an op<< overload for Person. Consider the following code: #include #include #include struct NameType { …
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
22
votes
5 answers

Interfaces, Inheritance, Implicit operators and type conversions, why is it this way?

I'm working with a class library called DDay ICal. It is a C# wrapper for the iCalendar System implemented in Outlook Calendars, and many many many more systems. My question is derived from some work I was doing with this system. There are 3 objects…
22
votes
3 answers

Is a copy constructor required when returning by implicit conversion?

The following code compiles fine in Visual C++ 2013, but not under GCC or Clang. Which is correct? Is an accessible copy constructor required when returning an object via an implicit conversion? class Noncopyable { Noncopyable(Noncopyable const…
user541686
  • 205,094
  • 128
  • 528
  • 886
22
votes
3 answers

convert number to letter javascript

I'm trying to convert numbers into letters. I'm making an array of divs that either need a number or a number and letter. so 1-3 are just 1-3. but 4-13 need to be a/4, b/5, c6 and so on. is there a way I can converts these numbers into letter…
Gambai
  • 651
  • 1
  • 7
  • 25
22
votes
5 answers

Why does C# allow an *implicit* conversion from Long to Float, when this could lose precision?

A similar question Long in Float, why? here does not answer what I am searching for. C# standard allows implicit conversion from long to float. But any long greater than 2^24 when represented as a float is bound to lose its 'value'. C# standard…
Amit Mittal
  • 2,646
  • 16
  • 24
21
votes
3 answers

Implicit conversion when overloading operators for template classes

I would like to know why implicit type conversion doesn't work with outside operator overloading on class templates. Here is the working, non-templated version: class foo { public: foo() = default; foo(int that) {} foo& operator…
pmjobin
  • 813
  • 1
  • 7
  • 15