Skip to main content
Filter by
Sorted by
Tagged with
0 votes
4 answers
532 views

When I am working with explicit interface implementations in C#, it often becomes necessary to cast an object to one of its interfaces in order to access a member of that interface. Because of the ...
Joseph Sturtevant's user avatar
12 votes
3 answers
7k views

And more specifically how does the BigInt works for convert int to BigInt? In the source code it reads: ... implicit def int2bigInt(i: Int): BigInt = apply(i) ... How is this code invoked? I can ...
OscarRyz's user avatar
  • 200k
27 votes
2 answers
3k views

Consider the following snippet: int i = 99999999; byte b = 99; short s = 9999; Integer ii = Integer.valueOf(9); // should be within cache System.out.println(new Integer(i) == i); ...
polygenelubricants's user avatar
5 votes
4 answers
4k views

I'm currently working on an application where I need to load data from an SQL database and then assign the retrieved values into the properties of an object. I'm doing this by using reflection since ...
Chris Boden's user avatar
1 vote
3 answers
456 views

I have an issue with MySQL 5.1. A datetime data type isn't implicitly casted to match a date column. SELECT * FROM my_table WHERE my_date_field = NOW() This request doesn't return any rows using ...
Savageman's user avatar
  • 9,497
8 votes
1 answer
364 views

Thanks to the implicit casting in compound assignments and increment/decrement operators, the following compiles: byte b = 0; ++b; b++; --b; b--; b += b -= b *= b /= b %= b; b <<= b >>= b ...
polygenelubricants's user avatar
32 votes
1 answer
3k views

In Java, when you do int b = 0; b = b + 1.0; You get a possible loss of precision error. But why is it that if you do int b = 0; b += 1.0; There isn't any error?
szupie's user avatar
  • 856
3 votes
6 answers
1k views

I have a situation where I would like to have objects of a certain type be able to be used as two different types. If one of the "base" types was an interface this wouldn't be an issue, but in my ...
Daniel Plaisted's user avatar
7 votes
1 answer
4k views

The following lines work when I enter them by hand on the Scala REPL (2.7.7): trait myTrait { override def toString = "something" } implicit def myTraitToString(input: myTrait): String = input....
pr1001's user avatar
  • 22k
2 votes
4 answers
2k views

The question is intended for lazy VB programmers. Please. In vb I can do and I won't get any errors. Example 1 Dim x As String = 5 Dim y As Integer = "5" Dim b As Boolean = "True" Example 2 Dim a ...
Shimmy Weitzhandler's user avatar
18 votes
1 answer
2k views

Option is implicitly convertible to an Iterable - but why does it not just just implement Iterable directly: def iterator = new Iterator[A] { var end = !isDefined def next() = { val n = if (...
oxbow_lakes's user avatar
11 votes
4 answers
3k views

I coded some calculation stuff (I copied below a really simplifed example of what I did) like CASE2 and got bad results. Refactored the code like CASE1 and worked fine. I know there is an implicit ...
Oscar Foley's user avatar
  • 7,065
2 votes
1 answer
340 views

MyClass c = 10; Is there any way to make this code work? I know that through the implicit operator overloading you can get the opposite to work: int i = instanceOfMyClass; Thanks
devoured elysium's user avatar
5 votes
1 answer
1k views

Background: Let's assume I've got the following class: class Wrapped<T> : IDisposable { public Wrapped(T obj) { /* ... */ } public static implicit operator Wrapped<T>(T obj) ...
stakx - no longer contributing's user avatar
1 vote
1 answer
165 views

Basically i want to do this. aa causes a bad cast exception. NOTE: o can be ANYTHING. It may not be B, it can be C, D, E, F etc. But this should work as long as o is a class that can typecast into A (...
user avatar
-5 votes
3 answers
286 views

Possible Duplicate: Identify the implicit cast and explicit cast int a = 2, b = 3; float f = 2.5; double d = -1.2; int int_result; float real_result; real_result = a * f; real_result = (float) a ...
user292489's user avatar
3 votes
4 answers
6k views

Is there any compiler that has a directive or a parameter to cast integer calculation to float implicitly. For example: float f = (1/3)*5; cout << f; the "f" is "0", because calculation's ...
Ziddiri's user avatar
  • 33
2 votes
2 answers
1k views

How does C++ determine implicit conversion/construction of objects few levels deep? for example: struct A {}; struct B: A {}; struct C { operator B() { return B(); } }; void f(A a) {} int main(void)...
Anycorn's user avatar
  • 51.8k
0 votes
4 answers
2k views

Hi I have a code like this, I think both the friend overloaded operator and conversion operator have the similar function. However, why does the friend overloaded operator is called in this case? What'...
skydoor's user avatar
  • 26k
3 votes
1 answer
933 views

I have problem with JavaConversions with 2.8 beta: import scala.collection.JavaConversions._ class Utils(dbFile : File, sep: String) extends IUtils { (...) def getFeatures() : java.util.List[...
nablik's user avatar
  • 153
2 votes
4 answers
485 views

Here's the code snippet: public static void main (String[]arg) { char ca = 'a' ; char cb = 'b' ; System.out.println (ca + cb) ; } The output is: 195 Why is this the case? I would ...
David's user avatar
  • 15k
27 votes
5 answers
8k views

Given Type a and Type b, how can I, at runtime, determine whether there's an implicit conversion from a to b? If that doesn't make sense, consider the following method: public PropertyInfo ...
Judah Gabriel Himango's user avatar
61 votes
3 answers
6k views

I'm a little stumped by this little C# quirk: Given variables: Boolean aBoolValue; Byte aByteValue; The following compiles: if (aBoolValue) aByteValue = 1; else aByteValue = 0; But this ...
MPelletier's user avatar
  • 16.8k
0 votes
2 answers
259 views

My program was:- #include < iostream.h> #include < conio.h> struct base { protected: void get() { cin>>a>>b; } public: base(int i=0, int j=0); ...
user avatar
1 vote
5 answers
1k views

My String class provides an operator char* overload to allow you to pass the string to C functions. Unfortunately a colleague of mine just inadvertently discovered a bug. He effectively had the ...
Goz's user avatar
  • 62.5k
8 votes
2 answers
832 views

Consider the following code: public class TextType { public TextType(String text) { underlyingString = text; } public static implicit operator String(TextType text) { ...
Kornelije Petak's user avatar
13 votes
3 answers
5k views

Given this class with an implicit cast operator: public class MyDateTime { public static implicit operator MyDateTime(System.Int64 encoded) { return new MyDateTime(encoded); } ...
Eric's user avatar
  • 2,069
7 votes
2 answers
2k views

In my code using reflections i wrote if (f.FieldType.IsAssignableFrom("".GetType())) I have a class that has an implicit conversion to strings. However the if statement above doesnt catch it. How can ...
user avatar
5 votes
1 answer
2k views

I have this function public static implicit operator MyClass(string v) { return new MyClass(v); } and write var.myclass = null;. This calls the implicit operator and passes null as string, which ...
user avatar
3 votes
1 answer
2k views

I have an mvc model class created and one of the properties is of type 'MyObject'. It also has a System.ComponentModel.DataAnnotations.StringLength attribute on it. MyObject as implicit cast ...
Jeremy's user avatar
  • 46.8k
3 votes
2 answers
1k views

I have a subset of a pointer class that look like: template <typename T> struct Pointer { Pointer(); Pointer(T *const x); Pointer(const Pointer &x); template <...
cvb's user avatar
  • 4,609
1 vote
4 answers
1k views

I already asked two questions related to what I'm trying to do (one resolved, one of which I will close soon). I know that C++ template instantiation does not allow any implicit conversions (see for ...
Victor Liu's user avatar
  • 3,663
1 vote
1 answer
570 views

While looking at the System.Type class under the Code Definition Window, I cannot seem to understand how an instance of this class is implicitly cast to string. For example, on the following code: ...
Alexandre Bell's user avatar
5 votes
3 answers
2k views

short s; s = (EitherTrueOrFalse()) ? 0 : 1; This fails with: error CS0266: Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?) Can anyone ...
J F's user avatar
  • 641
4 votes
4 answers
2k views

Let's say you have yourself a class like the following: public sealed class StringToInt { private string _myString; private StringToInt(string value) { _myString = value; ...
RCIX's user avatar
  • 39.7k
8 votes
5 answers
12k views

I have a class that encapsulates some arithmetic, let's say fixed point calculations. I like the idea of overloading arithmetic operators, so I write the following: class CFixed { CFixed( int ); ...
SadSido's user avatar
  • 2,551
2 votes
3 answers
7k views

I'm trying to deserialize json to an object model where the collections are represented as IList<T> types. The actual deserializing is here: JavaScriptSerializer serializer = new ...
Matt Kocaj's user avatar
  • 11.6k
2 votes
1 answer
1k views

I have a C# library that internal clients configure with VB.Net Their scripts are throwing an InvalidCastException where they really shouldn't. So the code is something like this (massively ...
Keith's user avatar
  • 157k
11 votes
6 answers
8k views

Is it possible to getting rid of error C2243? class B {}; class D : protected B {}; D d; B *p = &d; // conversion from 'D *' to 'B &' exists, but is inaccessible I had this error in my app ...
Lucas Ayala's user avatar
  • 2,449
5 votes
10 answers
5k views

Can someone tell me why the line with "//Compiles" compiles, and why the line with "//Doesn't Compile" does not? I don't understand why A would be implicitly convertible to B, not the other way ...
user avatar
9 votes
9 answers
11k views

I found the following rule in a coding standards sheet : Do not rely on implicit conversion to bool in conditions. if (ptr) // wrong if (ptr != NULL) // ok How reasonable/usefull is this ...
moala's user avatar
  • 5,384
1 vote
2 answers
660 views

How does JavaScript behave for the comparisons true == "true" and (0 == "0")?
faya's user avatar
  • 5,753
6 votes
4 answers
2k views

C++ does not allow polymorphism for methods based on their return type. However, when overloading an implicit conversion member function this seems possible. Does anyone know why? I thought operators ...
grefab's user avatar
  • 2,045
30 votes
4 answers
7k views

Why does: public class Addition { public static void main() { int a = 0; double b = 1.0; a = a + b; System.out.println(a); } } not compile but: public class Addition { ...
rawnd's user avatar
  • 375
23 votes
5 answers
11k views

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?
user avatar
3 votes
5 answers
2k views

When writing a class to act as a wrapper around a heap-allocated object, I encountered a problem with implicit type conversion that can be reduced to this simple example. In the code below the ...
Simon C.'s user avatar
  • 273
156 votes
16 answers
98k views

Is it possible to define an implicit conversion of enums in c#? something that could achieve this? public enum MyEnum { one = 1, two = 2 } MyEnum number = MyEnum.one; long i = number; If not, ...
Adam Naylor's user avatar
  • 6,370
64 votes
8 answers
27k views

I know you can use C++ keyword 'explicit' for constructors of classes to prevent an automatic conversion of type. Can you use this same command to prevent the conversion of parameters for a class ...
Superpolock's user avatar
  • 3,643
71 votes
1 answer
39k views

I have a generic class that I'm trying to implement implicit type casting for. While it mostly works, it won't work for interface casting. Upon further investigation, I found that there is a ...
Michael Meadows's user avatar

1
46 47 48 49
50