casting

What is the difference between static_cast and reinterpret_cast? [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-17 22:05:01
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: When should static_cast, dynamic_cast and reinterpret_cast be used? I'm using c function in c++, where a structure passed as a void type argument in c is directly stored that same structure type. eg in C. void getdata(void *data){ Testitem *ti=data;//Testitem is of struct type. } to do the same in c++ i use static_cast: void foo::getdata(void *data){ Testitem *ti = static_cast<Testitem*>(data); } and when i use

How to cast Object to boolean?

给你一囗甜甜゛ 提交于 2019-12-17 21:57:39
问题 How can I cast a Java object into a boolean primitive I tried like below but it doesn't work boolean di = new Boolean(someObject).booleanValue(); The constructor Boolean(Object) is undefined Please advise. 回答1: If the object is actually a Boolean instance, then just cast it: boolean di = (Boolean) someObject; The explicit cast will do the conversion to Boolean , and then there's the auto-unboxing to the primitive value. Or you can do that explicitly: boolean di = ((Boolean) someObject)

kSoap2 Android — Cast Class Exception (SoapObject)

痞子三分冷 提交于 2019-12-17 21:37:08
问题 I'm currently trying to retrieve an array from my webservice by using regular Ksoap implementation. However, when trying to access this array I am getting the following logcat error: 04-27 00:27:01.772: ERROR/AndroidRuntime(530): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{android.waiter/android.waiter.TablesActivity}: java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive It appears that for some reason Soap is not getting along with the way I

Required casting using C# ternary conditional operator

与世无争的帅哥 提交于 2019-12-17 21:31:23
问题 I am trying to figure out why casts are required in the following examples: bool test = new Random().NextDouble() >= 0.5; short val = 5; // Ex 1 - must cast 0 to short short res = test ? 5 : 0; // fine short res = test ? val : 0; // error short res = test ? val : (short)0; // ugly // Ex 2 - must cast either short or null to short? short? nres = test ? val : null; // error short? nres = test ? (short?)val : null; // ugly short? nres = test ? val : (short?)null; // ugly short? nres = test ? val

What happens when you cast from short to byte in C#?

拈花ヽ惹草 提交于 2019-12-17 21:29:25
问题 I have the following code: short myShort = 23948; byte myByte = (byte)myShort; Now I wasn't expecting myByte to contain the value 23948. I would have guessed that it would contain 255 (I believe the largest value for a byte). However, it contains 140, and it made me wonder why; what is actually going on behind the scenes? Please note that I am not looking for someone to solve the problem that 23948 cannot fit into a byte, I am merely wondering about the underlying implementation 回答1: Short is

Unexpected array to string conversion

只愿长相守 提交于 2019-12-17 21:23:49
问题 I'm trying to pack my data into objects before displaying them with ConvertTo-Json . The test case below shows perfectly how I'm dealing with data and what problem occurs: $array = @("a","b","c") $data = @{"sub" = @{"sub-sub" = $array}} $output = @{"root" = $data} ConvertTo-Json -InputObject $data ConvertTo-Json -InputObject $output Output (formatted by hand for clarity): { "sub": { "sub-sub": [ "a", "b", "c" ] }} { "root": { "sub": { "sub-sub": "a b c" } }} Is there any way to assign $data

How to cast bindingdatasource to datatable?

半世苍凉 提交于 2019-12-17 21:23:36
问题 I'm trying to cast the bindingdatasource to datatable using this code BindingSource bs = (BindingSource)gvSideMember.DataSource; DataTable tCxC = (DataTable)bs.DataSource; throws error unable to cast bindingsource to datatable then i tried this code private DataTable GetDataTableFromDGV(DataGridView dgv) { var dt = ((DataTable)dgv.DataSource).Copy(); foreach (DataGridViewColumn column in dgv.Columns) { if (!column.Visible) { dt.Columns.Remove(column.Name); } } return dt; } it again show me

Downcasting with Entity Framework

大憨熊 提交于 2019-12-17 20:53:41
问题 I have a project where I've defined in EF an Employer as a derived class of User . In my process I create a user without knowing whether it will eventually be an employer (or other kinds of users) and later I need to convert it. At first I tried (Intellisense indicated an explicit conversion exists): Employer e = (Employer) GetUser(); but at runtime I got: Unable to cast object of type 'System.Data.Entity.DynamicProxies.User_7B...0D' to type 'Employer'. so I tried to write a converter: public

What's the logical value of “string” in Python?

霸气de小男生 提交于 2019-12-17 20:34:52
问题 I erroneously wrote this code in Python: name = input("what is your name?") if name == "Kamran" or "Samaneh": print("That is a nice name") else: print("You have a boring name ;)") It always prints out "That is a nice name" even when the input is neither "Kamran" nor "Samaneh". Am I correct in saying that it considers "Samaneh" as a true? Why? By the way, I already noticed my mistake. The correct form is: if name == "Kamran" or name == "Samaneh": 回答1: Any non empty string in Python (and most

Function argument type followed by *&

点点圈 提交于 2019-12-17 20:31:24
问题 I have some code written by someone else in which some functions take arguments whose data types are followed by a *&. I'm used to functions taking one or the other, e.g. taking a "double *" or a "double &" but not both. It would have thought they would just cancel out. Here's an example, and this is all from their code which supposedly works: In a header file there's a function declared as: void someClass::foo(const unsigned int*& ubuff); Then in my main file, there's a pointer to some UINTs