casting

Allocating memory for unions and difference between union pointer and union of pointers

≡放荡痞女 提交于 2021-01-27 14:30:44
问题 Since my question here couldn't be confidently answered, I ask here again in hope that someone knows for sure: Is there any difference (besides syntactical) between a pointer to a union and a union that contains pointers to its elements? The generated assembly in this example is identical. As long as I'm never accessing the other members, is it allowed to allocate memory for only one of the members (which isn't the largest)? Regarding the 2nd question, 6.5.2.1 of the C89 draft says: The size

How do I cast a double to an int?

只愿长相守 提交于 2021-01-27 14:14:26
问题 I have a program that uses a formula to calculate the refurb on a unit (parts replaced on cableboxes that were damaged) divided by total units (cableboxes that went through refurb, but did not have any parts replaced). I looked up casting online, and the format for it is: int valuetoconvert = Convert.ToInt32; I'm doing that, but I still get the following error: Cannot implicitly convert type 'double to int. An explicit conversion exists(are you missing a cast?) What am I doing wrong? Can

If I've cast a subclass as its superclass, and call a method that was overridden in the subclass, does it perform the overridden or original method?

做~自己de王妃 提交于 2021-01-27 07:10:52
问题 Consider: Dog is a subclass of Animal , and Dog overrides Animal.eat() Animal[] animals = getAllAnimals(); for (int i = 0; i < animals.length; i++) { animals[i].eat(); } If Animal.eat() is overriden by Dog.eat() , which one is called when the method is called from an identifier of type Animal ( animals[i] ?) 回答1: The subclass method will be called. That's the beauty of polymorphism. 回答2: The subclass will be the only method call, unless the subclass calls the superclass like this: class Dog {

How to check VARCHAR(n) for well-formed XML before CAST/CONVERT

℡╲_俬逩灬. 提交于 2021-01-27 06:23:08
问题 My company has a logging table containing a VARCHAR(N) column in which a string is placed that is supposed to be XML, but as it turns out it is not always well-formed. In order to perform analysis on the logging (to identify error trends, etc.), I have been using a LIKE statement. However, this is remarkably slow. Recently, I discovered that SQL Server supports XQuery, so I started playing with it. The problem I'm running into is that I can't figure out a way to handle CAST/CONVERT errors

how to cast up to super class when there is an override function in the sub class

送分小仙女□ 提交于 2021-01-27 06:01:38
问题 A super-class Car and a sub-class Jaguar was created. The function info() -> Void in the sub-class overrided the super-class' function. A instance named theAuto of type Jaguar had been created. Problem: Seems I cannot up casts the theAuto to the type of Car , please see the code snippet and its comments class Car { func info() { print("You've got a car") } } class Jaguar : Car { override func info() { print("You've got a Jaguar") } } let theAuto = Jaguar() theAuto.info() // --> You've got a

Why does JSON null not cast to SQL null in postgres?

谁都会走 提交于 2021-01-27 05:24:34
问题 So the following PostgreSQL snippet returns null , as it should: select ('{"id": null}'::json->'id') Intuitively, one would expect the following statement to return null or an empty string: select ('{"id": null}'::json->'id')::TEXT Instead it returns the string "null". Why? Additionally, select ('{"id": null}'::json->'id')::INTEGER returns cannot cast type json to integer and select ('{"id": null}'::json->'id')::TEXT::INTEGER returns invalid input syntax for integer: "null" . (The use case

Why does JSON null not cast to SQL null in postgres?

杀马特。学长 韩版系。学妹 提交于 2021-01-27 05:24:09
问题 So the following PostgreSQL snippet returns null , as it should: select ('{"id": null}'::json->'id') Intuitively, one would expect the following statement to return null or an empty string: select ('{"id": null}'::json->'id')::TEXT Instead it returns the string "null". Why? Additionally, select ('{"id": null}'::json->'id')::INTEGER returns cannot cast type json to integer and select ('{"id": null}'::json->'id')::TEXT::INTEGER returns invalid input syntax for integer: "null" . (The use case

Why does JSON null not cast to SQL null in postgres?

我的梦境 提交于 2021-01-27 05:23:01
问题 So the following PostgreSQL snippet returns null , as it should: select ('{"id": null}'::json->'id') Intuitively, one would expect the following statement to return null or an empty string: select ('{"id": null}'::json->'id')::TEXT Instead it returns the string "null". Why? Additionally, select ('{"id": null}'::json->'id')::INTEGER returns cannot cast type json to integer and select ('{"id": null}'::json->'id')::TEXT::INTEGER returns invalid input syntax for integer: "null" . (The use case

Pandas cast all object columns to category

时光总嘲笑我的痴心妄想 提交于 2021-01-22 05:27:13
问题 I want to have ha elegant function to cast all object columns in a pandas data frame to categories df[x] = df[x].astype("category") performs the type cast df.select_dtypes(include=['object']) would sub-select all categories columns. However this results in a loss of the other columns / a manual merge is required. Is there a solution which "just works in place" or does not require a manual cast? edit I am looking for something similar as http://pandas.pydata.org/pandas-docs/stable/generated

How to cast a value from one enum to another in Java?

心不动则不痛 提交于 2021-01-21 02:31:26
问题 How can I cast a value from Enum1 to Enum 2 in Java? Here is an example of what I'm trying to do : public enum Enum1 { ONE, TWO, THREE; } public enum Enum2 { FOUR, FIVE, SIX; } So I want to do something like this: Enum2 en2 = (Enum2)ONE; Is it possible and how can I do that? Thanks in advance! 回答1: You cannot cast from one enum to another, however each enum has guaranteed order, and you can easily translate one enum to another (preserving order). For example: enum E1 { ONE, TWO, THREE, } enum