casting

Why can't pointer fit variable of different type, even though sizeof is same?

假如想象 提交于 2019-12-25 19:01:28
问题 Why the sizeof any pointer is 4 or 8 bytes, but it cannot fit any different variable? I get error while trying to assign a double pointer an int pointer value. int *int_ptr{nullptr}; float *float_ptr{nullptr}; double *double_ptr{nullptr}; long double *long_double_ptr{nullptr}; string *string_ptr{nullptr}; vector<int> *vector_ptr{nullptr}; cout << "sizeof int pointer is " << sizeof int_ptr; //8 or 4 cout << "sizeof float pointer is " << sizeof float_ptr; //8 or 4 cout << "sizeof double pointer

Why can't pointer fit variable of different type, even though sizeof is same?

守給你的承諾、 提交于 2019-12-25 19:01:20
问题 Why the sizeof any pointer is 4 or 8 bytes, but it cannot fit any different variable? I get error while trying to assign a double pointer an int pointer value. int *int_ptr{nullptr}; float *float_ptr{nullptr}; double *double_ptr{nullptr}; long double *long_double_ptr{nullptr}; string *string_ptr{nullptr}; vector<int> *vector_ptr{nullptr}; cout << "sizeof int pointer is " << sizeof int_ptr; //8 or 4 cout << "sizeof float pointer is " << sizeof float_ptr; //8 or 4 cout << "sizeof double pointer

JavaScript convert string to date time

社会主义新天地 提交于 2019-12-25 18:34:53
问题 I have a string that contains a datetime in the following format 2016-07-30 00:00:01.0310000 I need to convert this to a datetime object in JavaScript retaining the sub-seconds. If I use var d = new Date('2016-07-30 00:00:01.0310000'); Everything after 01 is dropped, how can I efficiently achieve this? 回答1: You'll have to parse the string yourself (which is quite simple, the only tricky bit is trailing zeros on the milliseconds value) and build the date using the Date(years, months, days,

Cast PropertyInfo to Collection

别等时光非礼了梦想. 提交于 2019-12-25 17:42:25
问题 How do I cast a collection property in order to manage it? Please, take a look the attached image. I need to get the collection by it's name, and then work with this collection to add, remove, etc. 回答1: You can't cast a PropertyInfo (which is just metadata information about the property) to its value type; you have to go through the GetValue method. That method will take an instance to retrieve from or null if it's static. The result is an object that you then cast: ICollection collection =

Cast an IList to an IList<t> using dynamic instantiation

纵然是瞬间 提交于 2019-12-25 12:04:51
问题 I am try to convert the following NHibernate query using dyanmic instantiation into an IList<t> rather than an IList. IList<AllName> allNames = (IList<AllName>)Session.CreateQuery( @"select new AllName( name.NameId, name.FirstName, origin.OriginId, origin.Description, name.Sex, name.Description, name.SoundEx ) from Name name join name.Origin origin") .SetFirstResult(skip) .SetMaxResults(pageSize); Running this I get the following error:- Unable to cast object of type 'NHibernate.Impl

Cast an IList to an IList<t> using dynamic instantiation

会有一股神秘感。 提交于 2019-12-25 12:04:41
问题 I am try to convert the following NHibernate query using dyanmic instantiation into an IList<t> rather than an IList. IList<AllName> allNames = (IList<AllName>)Session.CreateQuery( @"select new AllName( name.NameId, name.FirstName, origin.OriginId, origin.Description, name.Sex, name.Description, name.SoundEx ) from Name name join name.Origin origin") .SetFirstResult(skip) .SetMaxResults(pageSize); Running this I get the following error:- Unable to cast object of type 'NHibernate.Impl

JSONObject from HashMap - Cast to String failed

依然范特西╮ 提交于 2019-12-25 09:48:48
问题 I need to create a JSONObject from a HashMap of a custom class's toString and a float value. I tried the code below hoping that it would just work: public class MyClass { ... public String toString() { return "a nice string" } } HashMap<MyClass,Float> map = new HashMap<MyClass,Float>(); map.put(...); JSONObject json = new JSONObject(map); But I get: java.lang.ClassCastException: MyClass cannot be cast to java.lang.String What's the best way to create this JSONObject ? Thanks. 回答1: You need to

Spring Boot data-jpa and nativeQuery Postgres cast

…衆ロ難τιáo~ 提交于 2019-12-25 09:29:22
问题 I have a custom @Query in a repository that looks like this: SELECT * FROM topicaudit_c14001 WHERE auditdate >= NOW() AND auditdate <= NOW() + '1 hour'::INTERVAL AND accepted_status = 'ACCEPTED' AND reminder_sent = FALSE When I run this, I get the exception: org.hibernate.QueryException: Not all named parameters have been set: [:INTERVAL] Obviously it is interpreting the ::INTERVAL cast (Postgresql) as a named parameter and cannot fire the query since I don't provide a parameter. How can I

How do I get members of a dynamically typed array in C#?

戏子无情 提交于 2019-12-25 08:47:35
问题 I'm dynamically calling web services in my program using the WSProxy class here, and I need to parse the returned object to XML, or at least access the members inside the returned web service result. For example, if I receive an Array of StateCodes, I need to do: public object RunService(string webServiceAsmxUrl, string serviceName, string methodName, string jsonArgs) { WSDLRuntime.WsProxy wsp = new WSDLRuntime.WsProxy(); // Convert JSON to C# object. JavaScriptSerializer jser = new

I still get a “Arithmetic overflow” when I filter on a cast datetime even if I use IsDate()

情到浓时终转凉″ 提交于 2019-12-25 07:19:12
问题 I have a data set that I need to filter a date that is stored as a string (changing the source column to a DateTime is NOT a option, this data is coming from a 3rd party source that I can not control). One of the dates is malformed so if I do the following query I get one result select ClientID, StartDate from boarding_appts where isdate(StartDate) = 0 ClientID StartDate ---------- -------------------- 5160 5/6/210 12:00:00 If I do a cast(StartDate as datetime) I get " Arithmetic overflow