type-casting

Strange calculation problem in C multiply by 1.2 fails

I have this c code, where i need to calculate a dobule from a long. double result; long t2_value; t2_value = 72; result = t2_value * 1.2; Now this code crashes at "result = t2_value * 1.2;" only with the error "Vector 0000000006". Here is the strange thing, if i replace result = t2_value * 1.2; with result = 72 * 1.2; evythin...

Java: Typecasting to Generics

This method that uses method-level generics, that parses the values from a custom POJO, JXlistOfKeyValuePairs (which is exactly that). The only thing is that both the keys and values in JXlistOfKeyValuePairs are Strings. This method wants to taken in, in addition to the JXlistOfKeyValuePairs instance, a Class<T> that defines which data ...

Casting problem cant convert from void to float C++

as i said i get this horrible error i dont really know what to do anymore float n= xAxis[i].Normalize(); thats where i get the error and i get it cuz normalize is a void function this is it void CVector::normalize() { float len=Magnitude(); this->x /= len; this->y /= len; } i need normalize to stay as void tho i tried norma...

how to get output of a variable as float value

hi..i m having the follwing problem.. want to get the result in float suppose int a= convert.toint32(textbox1.text); int b= convert.toint32(textbox2.text); float ans= math.sqrt(a*b); label1.text= ans.tostring(); output.. a=7 b=3 ans should be= 4.582 but i get an error cannot implicitly convert type 'double' to 'float'. pls hel...

Type casting problem with java for-each loop

Hi, I have traced an issue with an application I am developing, it is giving me a type cast exception. Funny thing is it is saying it cannot cast "entities.Movie cannot be cast to entities.Movie"?! movies is an ArrayList. try { movies = getMovies(); } catch (Exception e) { e.printStackTrace(System.out); } fi...

Passing a class ("Country.class") as an argument in Java

I'm trying to make a method that takes an argument of Country.class, User.class etc, and returns argument.count(). All the possible classes that I would give to this method extend from Model and have the method count(). My code: private static long <T> countModel(Model<T> clazz) { // there is other important stuff here, which prev...

Haskell - how to cast types?

I am trying to do following: 10 ** length xs * x but I get: No instance for (Floating Int) arising from a use of `**' ...

[VB.Net] Typecasting generic parameters.

Hello world! Using the following code: Function GetSetting(Of T)(ByVal SettingName As String, ByRef DefaultVal As T) As T Return If(Configuration.ContainsKey(SettingName), CType(Configuration(SettingName), T), DefaultVal) End Function Yields the following error: Value of type 'String' cannot be converted to 'T'. Any way I coul...

Difference in casting in the following 2 methods

Possible Duplicate: casting vs using the as keyword in the CLR hi, can somebody please tell me what is the difference between the following two statements, because both of them give me the same results. Also i want to know which is better. Label lblSome = e.Item.FindControl("lblMyLable") as Label; && Label lblSome = (Label...

C# Bug or Brain Teaser? Cast working only with Coalesce (??) Operator

This is very strange, maybe someone can explain what's happening, or this is a bug (though I tend to think that this is probably just something intricate about C#). The following code throws the error "Cannot implicitly convert type 'uint?' to 'uint'.": public void Test(UInt32? p) { UInt32 x = p; } However, this code works witho...

Window Wrapper Class C++ (G++)

Hi all, I am attempting to learn about creating windows in c++, I have looked at an article about creating a wrapper class but I don't really understand it. So far I know that you can't have a class method WndProc (I dont know why) but honestly, that is all. Can somebody give an explanation, also explaining the reinterpret_cast? Here is ...

Avoid incompatible pointer warning when dealing with double-indirection

Assuming this program: #include <stdio.h> #include <string.h> static void ring_pool_alloc(void **p, size_t n) { static unsigned char pool[256], i = 0; *p = &pool[i]; i += n; } int main(void) { char *str; ring_pool_alloc(&str, 7); strcpy(str, "foobar"); printf("%s\n", str); return 0; } ... is it pos...

How do I get generics to work with return values that require careful casting?

I've got some data access layer code calls a stored proc and returns scalar values of various datatypes. The syntax is ExecuteDecimal, ExecuteString, etc. I want it to be Execute<string> or Execute<decimal> I try this implementation and I can't compile, unless I'm doing casting using "(T) value", if I try to check the type and call a ...

Converting Generic Type into reference type after checking its type using GetType(). How ?

i am trying to call a function that is defined in a class RFIDeas_Wrapper(dll being used). But when i checked for type of reader and after that i used it to call function it shows me error Cannot convert type T to RFIDeas_Wrapper. EDIT private List<string> GetTagCollection<T>(T Reader) { TagCollection = new ...

Parsing a dynamic enumeration

We are using a Microsoft ERP which dynamically exposes web services. The services generated by the service is out of our control. We have no say so in how the objects, including the type definitions, are created and exposed. When a new method is added or removed from the web service, all of the type enumerations are renumbered and ever...

automatic casting (or not?) in c

I'm trying to learn C from a Ruby/PHP/Java background, and I've found that you almost always explicitly cast things (at least in tutorials). Like, I always see things like double x, y; x = 1.0; /*...*/ y = x*5.0; However, it seems that on my Mac's version of GCC, automatic casting works. Is leaving the .0 on things just a matter of ...

C++ Type Casting: benefit of using explicit casts?

What are benefits of using these operators instead of implicit casting in c++? dynamic_cast <new_type> (expression) reinterpret_cast <new_type> (expression) static_cast <new_type> (expression) Why, where, in which situation we should use them? And is it true that they are rarely used in OOP? ...

Implicit typecasting in C (Converting 32 bit unsigned in to 8 bit u int)

My question looks a lot like http://stackoverflow.com/questions/2810280/how-to-store-a-64-bit-integer-in-2-32-bit-integers-and-convert-back-again (I have an unsigned 32 bit I need to put into 4 unsigned 8-bit variables in C) but My question is whether this: uint8_t a; uint32_t b; a = b; guarantees that a is filled with the eight r...

Problem with type-casting array of strings in C

I am trying to read a large list of English words from a text file to array of strings. The number of words is 2016415, and maximum length of a word is 69 characters. If I define array like "char data[2016415][70]; " then I get stack overflow when I run the program. So I am trying to use calloc() instead, however I can't understand how...

Why do I have to typecast an int in a ternary expression?

Possible Duplicate: Conditional operator cannot cast implicitly? I have run into a peculiar situation and want to know why I have to do it. I'm using .net 3.5. This works: short foo; if (isValid) foo = -1; else foo = getFoo(); This does not work: short foo; foo = isValid ? -1 : getFoo(); I have to typecast -1: ...