FAQ Database Discussion Community


Convert Nothing into Nullable(Of )

.net,vb.net,casting,nullable
I want to convert a null value into a Nullable(Of )-Type. I can cast it with CType(), but not convert it with System.Convert.ChangeType(). Is there a way to do so? Why it throws an exception? Dim b as Boolean? = CType(Nothing, Boolean?) 'ok System.Convert.ChangeType(Nothing, GetType(Boolean?)) 'Throws System.InvalidCastException ...

How to assign string to unsigned char[] in c++

c++,casting,unsigned
I'm having difficulty understanding typecasting, and i am attempting to improve my understanding by assigning the contents of a string to an array of unsigned chars. I expected the code below to print true, but it does not. unsigned char a[10]={0,1,2,3,4,5,6,7,8,9}; string b="5"; if(a[5]==(unsigned char)atoi(b.c_str())){ cout<<true<<endl; } What am I...

the usage of the long double

c,casting,double,long-integer
The functions purpose is to calculate the square root of a number using the Newton-Raphson method. I included a printf routine in the while loop so I can see the value of root 2 get closer and closer to the actual value. I originally used float to define epsilon but...

Cast from unknown type in c#

c#,casting
I have a object that contain a value in string and a origin Type that is in a field. class myclass { public string value; public Type type; } myclass s=new myclass(); s.value = "10"; s.type = typeof(int); Type tt = s.type; row.Value[ind]= s[0].value as tt; //i have error here...

Cast between unsigned and signed. How to?

c++,casting
I have a question, being a student I have to use OpenSSL. My task is to calculate a RSA signature with blinding, and it uses both char and unsigned char. I said this in case anyone is wondering why I'm using these types, char and unsigned char, so intricately. My...

Cast from generic to generic

c#,generics,casting
In a nutshell I'm trying to get this code working: class it<X> { X[] data; int pos; public Y get<Y>() { return (Y) data[pos]; } } Basically, I have lots of arrays of different primitives that needs to be processed another place as different primitives. The former code won't compile...

Cast a stage child movieclip into a custom class extends movieclip AS3

arrays,actionscript-3,flash,casting,movieclip
I'm creating a program where I add multiple Movieclips to the stage in Flash, instance name them 'item_#' per frame, and at runtime I pull these children into an array and dynamically cast them to a custom class called 'Item' which extends MovieClip. function loadUpItems(): Array //loads items into ItemArray{...

DB2 Convert from YYYYMMDD to Date

sql,date,casting,db2
I have a column that stores a dat as char in the format 'YYYYMMDD'. Now I want to convert it to a real date. I tried select cast (DATEFIELD as DATE) as MyDate But it only returns the old YYYYMMDD format labeled as 'DATE'. What am I doing wrong?...

Combobox Datasource assign to Datatable

vb.net,combobox,casting,datatable
How to convert Datasource of a Combobox to Datatable in VB.net? I know how to assign datatable to combobox. In this case I need to do it opposite way. Like: dim dt as DataTable = combobox1.DataSource Is this possible?...

Spring, Java : Passing Generic object List as return type

java,spring,spring-mvc,generics,casting
I am working on a Spring-MVC application in which depending upon the mode set by the user, I have to return a List of either Object1 or Object2. Ideally, I can create two controller methods and send the List appropriately, but I would like to know is there any way,...

Java: must cast to short, cannot use shorthand 'S'

java,casting,java-7,short
I am trying to call a function that requires a short value. The following works: i.setDamage((short) 10); However, this does not: i.setDamage(10S); According to the IDE I am using, this should work. Why does it not? I am using Maven and Java 7....

Unusual static_cast syntax

c++,casting
I managed to track a bug down to the following expression: foo(static_cast<T>(a, b)); // Executes specialisation 1 The closing bracket was in the wrong place. The correct statement should have been: foo(static_cast<T>(a), b); // Executes specialisation 2 I've never seen static_cast used with the form (a,b), or seen it described...

Java Interfaces Casting

java,interface,casting
Imagine we have class C that implements interfaces I and J declared as ; I i = new C(); why do these 3 not give errors (especially the last one): 1) C c = (C)i; 2) J j = (J)i; 3) i = (I)null; thanks in advance. ...

cannot convert from int to byte [duplicate]

java,casting,integer,byte
This question already has an answer here: Is addition of byte converts to int is because of java language rules or because of jvm? 4 answers I have a rather simple - but for me confusing - question. Assume the byte variabels a,b,c: byte a = 5; byte b...

Cast from 'Int?' to unrelated type 'NSNumber' always fails

ios,swift,casting
When I try to do the line below, I dont get a warning (not an error). What is this am I am doing something bad? I am trying to cast the integer earningsSoFar to a NSNumber because I want to get the .stringValue out of it. I want to understand...

fn:sum error “cannot cast to xs:double”

xpath,casting,sum,xquery
I'm trying to add up multiple nodes (names & amount of nodes uncertain). performing the query for $x in //onboard/* return $x returns this (and more) <total> <one/> </total> <total> <one>124</one> <two>1</two> <three>0</three> </total> <total> <one>46</one> </total> <total> <one>129</one> <two>1</two> <three>0</three> </total> <seafarers> <one>149</one> <two>3</two>...

converting varchar to Int SQL SERVER

sql,sql-server,casting
I needed help with something I am not entirely sure how to resolve. This is my code : SELECT DISTINCT Nr_of_Times_Cust_No_Appears=CASE WHEN CAST(a.TV_Code AS Int)-CAST(BB_Code AS Int)=0 THEN COUNT(*) OVER (PARTITION BY BB_Code) ELSE 'Not same' END FROM table Basically, the above code is meant to make sure that the...

c: change variable type without casting

c,types,casting
I'm changing an uint32_t to a float but without changing the actual bits. Just to be sure: I don't wan't to cast it. So float f = (float) i is the exact opposite of what I wan't to do because it changes bits. I'm going to use this to convert...

Converting String into NSDate in array of dictionaries

arrays,swift,casting,nsdate,nsdictionary
I am doing some requests with an API that returns me the following sample : [{ id = 1004; "planning_id" = 7; "started_on" = "2015-05-14";}, { id = 1380; "planning_id" = 8; "started_on" = "2015-05-16";}, { id = 1382; "planning_id" = 8; "started_on" = "2015-05-18"; }] As you can see,...

Declare variables of a type indicated by a pointer

c++,c,pointers,types,casting
I have: const char *ptr = "int"; If I have to declare using ptr: int a; ptr can point to anything arbitrary char, string, <anythihg>. I have to delcare a variable of that type what ptr is pointing at. Is it possible?...

Google coding challenge not detecting int

java,casting
The point of this program is to get a long variable like "1256" and add them up digit by digit until you're left with a single digit integer. So 1 + 2 + 5 + 6 = 14, 1 + 4 = 5, return 5. When I try to verify...

C++ - Safety of reinterpret_cast for pointer-to-primitives

c++,casting,type-safety,reinterpret-cast
I've come across a piece of code in a project I'm evaluating, and wanted to know if the following cast is safe: void func(unsigned long* input); ... int data = 42; func(reinterpret_cast<unsigned long*>(&data)); // Casting to remove compiler warnings about data type not matching type expected I know that with...

convert String to AnyObject in swift

swift,casting
I have a static string variable struct numb { static var selectedNumber: String = String() } I am trying to unwrap ( while casting it as AnyObject) the value and assign it to messageComposeViewController if let textMessageRecipients :AnyObject = numb.selectedNumber { messageComposeVC.recipients = textMessageRecipients as? [AnyObject] messageComposeVC.body = "Testing 123!"...

For what reason printf does not correctly display the float?

c,casting,floating-point,printf
I hoped that in all cases showed 2.33, however, for what reason only in the second case this happened? printf("Without cast: %0.2f\n", 7 / 3); // Whitout cast: 0.00 printf("With cast: %0.2f\n", (float) 7 / 3); // With cast: 2.33 float x = 7 / 3; printf("With var: %0.2f\n", x);...

Is dynamic_casting through inheritance hierarchy bad practice?

c++,oop,inheritance,casting
I have got the following data structure: class Element { std::string getType(); std::string getId(); virtual std::vector<Element*> getChildren(); } class A : public Element { void addA(const A *a); void addB(const B *b); void addC(const C *c); std::vector<Element*> getChildren(); } class B : public Element { void addB(const B *b); void...

jooq - select removes varchar length information of cast

sql,sql-server,casting,varchar,jooq
when call this code DSLContext dslContext = DSL.using(SQLDialect.SQLSERVER); dslContext.select(DSL.cast(field, SQLDataType.VARCHAR.length(255))); the select statement removes the information of the varchar length. The DSL.cast() method returns cast("fieldName" as varchar(255)) and the select returns select cast("fieldName" as varchar). The problem ist that in SQLServer the cast without length information cuts the result after...

In Java, How do I cast a Realm Object into the class I wish to write to the Database?

android,class,object,casting,realm
I am currently working on a project where my Database has a very large number of tables (Approx 60 total). I am working to create the Database Helper class that will function as the writer/ reader to/ from the database. And example of my write method would be this: public...

How to cast a compact type in Vala?

casting,vala
I am using the gobject-introspection-1.0 library from Vala to dynamically load gir modules. As I need to call an initialization function having a fixed name, I retrieve a BaseInfo object from Repository.find_by_name. Now, I want to invoke this function with GI.CallableInfo.invoke, which needs a GI.CallableInfo object. Luckily, GI.CallableInfo inherits from...

Template cast operator when T is QPointF

c++,qt,templates,casting
I have a custom two dimensional point type, which has a template cast operator: struct MyPoint { double x, y; template < typename T > operator T() const { return T{ x, y }; } }; All works fine for std types: auto p1 = MyPoint{ 1, 2 }; auto...

Making a convenient logging function for Try[T], but got stuck because of the type system

scala,casting,type-conversion,scala-generics
I wonder if this can be done using Scala's type system. Basically, I want to make a logging method which accepts a result of type Try[T] and prints out a message that differs a bit depending whether result is a Success or a Failure For example, the signature might look...

Cast StringCollection as List [duplicate]

c#,casting
This question already has an answer here: How to convert List<string> to List<int>? 6 answers I have a StringCollection object being passed through a ReportParameter object, and I need to get it to be a List<int> instead. So far, I've tried this List<int> ids = (parameters != null) ?...

Difference between (float *) & *(float*) in C

c,pointers,casting
I am trying to understand the pointer concepts in-depth. In the following code, #include <stdio.h> int main() { int i = 10; int *iptr = &i; printf("(float)* : %f\n", (float)*iptr); printf("(float*) : %f\n", (float*)iptr); printf("*(float*) : %f\n", *(float*)iptr); return 0; } output: (float)* : 10.000000 (float*) : 10.000000 *(float*) :...

Increment number in Dictionary

swift,dictionary,casting
I have a Dictionary [String:AnyObject] which contains some keys and values. I want to increment a key to which value is of type Double. I can do it this way: let nr = dict["number"] as! Double dict["number"] = nr + 10 But I dont like that way so Im wondering...

Group By Date and SUM int - Date formatting and Order

sql-server,date,casting,order,group
I'm trying to get the SUM of the quantity sold on a day. I need the results to be in ORDER BY date. The query below gives me the exact result I need, except the date is not formatted to what I need. SELECT CAST(Datetime AS DATE) AS 'date', SUM(quantity)...

Avoid Type Casting During Data Processing

java,oop,inheritance,design,casting
I can't seem to figure out the best approach to tackle the following problem. Let's say there is an abstract base class with several concrete subclasses: public abstract class AbstractType { /* common properties */ } public class TypeA { /* properties of type A */ } public class TypeB...

When we typecast the int to double does the actual address where int is stored is get changed?

c,casting
I want to know that when we typecast the int to double does the actual result where int is stored is get changed or increased? because int is of 4 bytes(lets assume) and when we it get typecast to double which is of 8 bytes(assumption) then does the size also...

Downcasting doesn't work and functions called from object own class instead of where the function is (Java)

java,class,oop,methods,casting
i have this classes hierarchy: public class Musician { private String name; public String instrument; public Musician(String name, String instrument) { this.name = name; this.instrument = instrument; } public String getName() { return name; } public String getInstrument() { return instrument; } private String getClassName() { return "Musician"; } public...

Cannot convert int {Class}::* to int*

c++,casting,int
When I try to call a function, passing in a reference to my variable which has the type int, to the function which takes a type of int, I get an error that seems to point out that the int is the type of the class it was declared in,...

Properly casting a `void*` to an integer in C++

c++,pointers,casting
I'm dealing with some code that uses an external library in which you can pass values to callbacks via a void* value. Unfortunately, the previous person working on this code decided to just pass integers to these callbacks by casting an integer to a void pointer ((void*)val). I'm now working...

Getting the count (number of items) in a json response in swift

ios,json,swift,casting,afnetworking
I am on the process of learning swift now. I have used ANetworking (library in Obj C) in my swift code. I have successfully been able to return the parsed JSON. However I would want to find the count of the json items that are returned. Here is what I...

Program not compiling after casting pointer

c,pointers,casting,compiler-errors,void-pointers
Here is my code: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <netdb.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> int main (void) { struct addrinfo hints; memset (&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_CANONNAME; struct addrinfo *res; getaddrinfo ("example.com", "http", &hints, &res); printf ("Host: %s\n",...

Label convert findcontrol

c#,gridview,casting,label
I am not very experienced and perhaps I am asking a stupid question. I'm trying to delete a row inside this gridview. To do this, I call a method deleteDettagliDocument(id_row) to perform a DELETE from my DB. This method takes an integer as parameter but the control is a Label...

(*var)[n] what does it mean in c++

c++,pointers,casting
What does (*var)[n] mean in C++? In this code I know that it refers to getting the captured string from regex matches of group n, but I don't understand why this doesn't work: *var[n] //edit: oh duh, that would be a multiplication what's up with the parenthesis? reminds me of...

Is this an unavoidable signed and unsigned integer comparison?

c++,casting,unsigned,signed
Probably not, but I can't think of a good solution. I'm no expert in C++ yet. Recently I've converted a lot of ints to unsigned ints in a project. Basically everything that should never be negative is made unsigned. This removed a lot of these warnings by MinGW: warning: comparison...

How to split string in chars and get code of each char in freemarker?

casting,char,freemarker
I think that I can split using this: <#list str as c> ... </#list> But then I need to convert this char to byte and add it to another number. In most languages it will be like so: int num=53, res; char c='g'; res=num+c;//c cast to byte and then to...

Cast sql_variant into data_type provided as varchar

sql,sql-server,stored-procedures,casting
I have a following sql table: Types table -------------------------------------- |Name(varchar(50))|Type (varchar(50))| -------------------------------------- | Car | varchar(50) | | Apples | int | -------------------------------------- I am using another tables for storing values such as: Apples table: ---------------------------- |Value (providedType - int)| ---------------------------- |50 | |60 | ---------------------------- To insert values into...

Convert CWnd* to myControl*

c++,casting,mfc,control,cwnd
I am trying to convert a CWnd* pointer to a custom control pointer. The custom control just extends CEdit. Below is what I have. pWnd was passed in. it is a CWnd*. calEdit* test = (calEdit*)pWnd->GetDlgItem(pWnd->GetDlgCtrlID()); When I try to debug and see what the value of test is, none...

What does *(*)() mean?

c,pointers,memory,casting
I recently came across the following C-code: *(STRUCT_T*)(0xC6) STRUCT_T is a typedefed structure. Can someone explain what this means? My guess: STRUCT_T* casts the address 0xC6 to a structure pointer and * then retrieves the value (struct) stored at the address 0xC6?...

Doubts about __bridge, _bridge_retain and _bridge_transfer

ios,objective-c,memory,types,casting
I have read about __bridge, _bridge_retain and _bridge_transfer and did some experiments. However the output does not coincide with what I was expecting. In particular, I have the following code: @interface ViewController () @property (nonatomic, strong) NSString *test; @end @implementation ViewController CFStringRef cfString; - (void)viewDidLoad { [super viewDidLoad]; self.test =...

F# cast / convert custom type to primitive

types,casting,f#,primitive
I've designed my app domain with custom F# types, but now it seems like these custom types will be a PITA when I want to actually use the data for various tasks... i.e. writing values to a CSV file, using other libraries that rely on primitives, etc. For example, I...

Argument Type Problems

casting,compiler-errors,fortran
Why am I getting the following error d = Atan ( 1_Real32 / 110443_Real32 ) 1 Error: 'x' argument of 'atan' intrinsic at (1) must be REAL or COMPLEX The funny thing is that I get no problems when I use d = Atan ( Real(1,Real32) / Real(110443,Real32) ) ...

Typecasting vs function to convert variable type in PHP

php,casting
Is there any difference between typecasting and using a function to convert a variable to some type? (float)$var VS. floatval($var) If there are, when one of those should be used instead of the other?...

Java: Implementing an interfacing by inheriting a class

java,inheritance,interface,casting
Time-appropriate greetings :) Working in Java, I have an Interface A. All implementors of this Interface also extend class B, but B does not implement A. In a class where we use an instance of A (referenced as A), it is cast to a B Reference so that we can...

Unable to use CAST Function

sql-server,datetime,casting
Im unable to execute a CAST Function in MS SQL Server when working with a DATE Expression. CAST(CAST('2012-10-01' - DateHired AS INTEGER) / 365 AS INTEGER Error Msg;The data types varchar and date are incompatible in the subtract operator. DATEADD ( DAY, '2012-10-01' - DateHired)/ 365 AS YearsWithSchool Error Msg;...

Can I determine the number of dimensions of a multi-dimensional list if it contains empty lists?

java,list,generics,multidimensional-array,casting
I have two classes A and B and a method B convertAToB(A a). Now I want to make a method which converts multi-dimensional (or even single-dimensional) lists of A to B. For example: Given a List<A> it should return a List<B> Given a List<List<A>> it should return a List<List<B>> and...

Google Cast Media Player Library - for streaming from Local Device

ios,casting,chromecast,google-cast
Despite reading the documentation it not not clear to me exactly what " Google Cast Media Player Library" is and whether it is the route I need to take for my Chromecast app. What I am trying to achieve is to play media from my local IOS device on Chromecast....

how divided integer is converted to floating point number with decimal [duplicate]

java,casting,floating-point
This question already has an answer here: Division of integers in Java 4 answers if 123/33 prints out 3 and 3 is an integer if we cast it to float ( (float)123/33 )how do we get the decimal places from the integer 3. does 3 contains floating points internally...

Postgres return null values on function error/failure when casting

sql,postgresql,casting,plpgsql
I am attempting to convert text values to timestamp values. For the following table called a: id | c1 ----+-------------------- 1 | 03-03-2000 2 | 01-01-2000 3 | 12/4/1990 4 | 12 Sept 2011 5 | 12-1-1999 12:33:12 6 | 24-04-89 2:33 am I am attempting to perform a select...

Cast map structure to void pointer and dereference

c++,dictionary,casting,void-pointers,dereference
I have been trying to cast a map structure to a void pointer and cast it vice versa. void addToMap(void *data){ // add some elements to the map } map<string, vector<myStruct> > myMap; addToMap(&myMap); I am trying to send myMap to addToMap function as an argument and add some elements...

Casting a String Into a Function in R

r,function,casting
I have a Shiny app in R where I want users to be able to create functions on the fly by entering text in a text box. To enable this functionality, I would like to know the following: How would I go about casting a string object containing a function...

Is casting necessary in the following arithmetic sum?

c,casting,overflow
short a; short b; short x; int c = (int)a + (int)b * (int)x; Can I dispense with the (int) casts in this case? i.e. when compiler performs the multiply and add, does it work with int intermediate variables, or with short intermediate variables? Edit: what about for other types?...

Safe and Efficient Type Punning in C++

c++,casting,type-punning
uint32_t Seed() { uint64_t seed = GetSomeReasonable64BitIntegerSeed(); return *(uint32_t*)&seed ^ *((uint32_t*)&seed + 1); } Above is not real code, but that's basically what the real code does. I got a warning from g++ that it violates strict aliasing, googled it, and okay I want to fix it. I found this...

How to cast generic parameter to generic interface?

c#,generics,casting,extension-methods
I want to have an extension method to print all contents of IEnumerable< X > public static IEnumerable<T> log_elements<T>(this IEnumerable<T> collection, bool recursive = true) { Form1.log("["); foreach (T i in collection) if(recursive&&(i.GetType().GetGenericTypeDefinition()==typeof(IEnumerable<>))) (IEnumerable<>)i.log_elements();//This doesn't work else Form1.log(i); Form1.log("]"); return collection; } If it contains IEnumerable< Y >, the method...

Casting a list of objects to another one

c#,linq,casting,lambda,dao
I have the following classes(entities): Entity(base class, has 3 props) & Category(derives from Entity and adds some other props) The problem occurs when I read data from the DB(the fill method returns a list of Entities) and the compiler doesn't allow me to cast from Entity to Category. The problematic...

calculation of limits of char without using macro definitions

c,casting,bitwise-operators
I was trying to calculate the limits of type char using the following expression. (char)(~(unsigned char)0 >> 1) I expected this to be equal to 127 but answer is -1. Then I replaced this expression. ~(unsigned char)0 by (unsigned char)~0 This one is giving the correct answer So how are...

Python: Transform a unicode variable into a string variable

python,unicode,casting,web-crawler,unicode-string
I used a web crawler to get some data. I stored the data in a variable price. The type of price is: <class 'bs4.element.NavigableString'> The type of each element of price is: <type 'unicode'> Basically the price contains some white space and line feeds followed by: $520. I want to...

Assigning a concrete Task to a variable of type Task

c#,inheritance,interface,casting,task-parallel-library
Consider a class Foo which wholly implements IFoo. Concurrently, consider a task Task<IFoo>. Why is it that when the following is called, a compilation error is thrown; Task<IFoo> task = Task.Factory.StartNew(() => new Foo()); The compiler states that it cannot convert from source type Task<Foo> to Task<IFoo>. While this makes...

create utility to cast objects to beans in java

java,class,object,casting
i am working on a helper class to pass a class instance and object to (object usually a JSON body) and can't quite get casting to work when using generic Class. if it does return class, it barks that my bean can't be cast to Java.lang.Class, or the below issue...

In a MySQL select statement, can I split a text column and then sum the parts as floats?

mysql,select,casting,split
I have a MySQL column that is defined as text. The column, if not null, always contains a list floats separated by a newline character. I have been tasked with making the total amount of those floats searchable with min and max constraints. In the where clause, I would like...

byte to int type conversion network application

java,c,casting,network-programming,type-conversion
I'm sending from my android phone integer as byte with the following code(I put only the needed chunks): private byte[] intToByteArray ( final int i ) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); dos.writeInt(i); dos.flush(); return bos.toByteArray(); } //thread sender data = new byte[16];...

Automatic type casting while passing method parameters

java,casting
There are around 10 different types of 2D arrays of varied sizes. eg: int arr1[][]; float arr2[][]; long arr3[][]; String arr4[][]; Each array needs to be printed at different intervals during the program execution. There is a method defined print2DArray() which takes the 2D array as parameter calculates the number...

Is std::string::npos == -1 always true?

c++,casting,language-lawyer
The title is relatively self explanatory. I recognize the similarity to other answers, but all of those have different arrangements of operators (and therefore different casting rules). So I require an answer that clarifies this particular case. If someone could point out the section of the standard that explains this,...

Casting a pointer by reference

c++,casting,parameter-passing,pass-by-reference
I came across something I don't understand well. Let's suppose I want to pass a character pointer to a function that takes a reference to a void pointer. void doStuff(void*& buffer) { // do something } I would usually do something like this : int main() { unsigned char* buffer...

R is passing list index value as numeric, how to force pass as characters

r,casting,character,r-factor
I have some code which passes a list containing some strings to another function. Thing is the new function doesn't use the string associated with the index, but rather uses the index number. How do I force it to use the string value behind the index value? My code for...

Extract 2nd and 3rd value from char array and cast it as short (2 bytes). In C

c,arrays,pointers,casting
Say I have an unsigned char (or byte) array. I want to take array[1] and array[2] from memory and cast it as short int (2 bytes). Something similar to how a union works, but not starting from the first byte. Example: #include <stdio.h> void main() { unsigned char a[28]; unsigned...

Objective C: Accessing properties of an object instance that's in an array that's a property of an object

ios,objective-c,osx,properties,casting
This seems like it would be a simple thing to do but I'm having trouble finding the exact syntax. I have an object called myObject. It has a property called companies. Each object in that array is an object of type Company which has a property called myid. I'm simply...

Cast button not displaying

android,casting,chromecast,google-cast
I know its a quite common problem although searching through stackoverflow and android developers site left me without whole picture. Is it necessary to register application in Google Cast SDK Developer Console? I don't need custom receiver so I can use CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID, can I? If I register application and receive...

Base to derived class conversion does not result in null

c#,casting,subclass,base-class
As long as I know, we can't directly convert a base class to a derived (sub) class, because the base is not an instance of the derived and thus it'll result in null. I have two classes, one derives from the other. I'm trying to figure out why I can...

final casting concept doesn't apply for overloading

java,casting,method-overloading
In my casting class, teacher taught us an interesting fact as follows. class Casting { public static void main(String args[]){ int i = 10; byte b = i; System.out.println(b); } } We got an error java:5: possible loss of precision And then we changed the code as follows class Casting1...

Virtual destructor of base class is not called when downcasting is done via dynamic cast

c++,casting,downcasting
When I run the following code, I get the following issue. Deleting derived pointer d1 does not call the destructor of the base class. Deleting derived pointer d2 calls the base destructor. Why is the type of cast (dynamic or static) affecting whether base destructor is called or not. class...

Scala generic cast from String function

scala,generics,casting
How can I write a function to convert a String to a generic type (Double, Int, Float, etc.)? Here's pseudocode for the functionality I'm looking for: def castFromString[A: Manifest](value: String): A = { if (A == Double) { parseDouble(value) } else if (A == Int) { parseInt(value) } else {...

Typecasting int to char, then search array

c,arrays,string,casting,int
I have a problem with typecasting in C. Let me explain my problem first: I have a 2-dimensional array of integers that is filled with numbers from 0-9 (its a sudoku and 0 means a empty space). Then I have a second array and that is a 3-dimensional char array....

Unconstrained type parameters casting

c#,.net,types,casting
My situation: interface ISomeInterface { void DoSmth<T>(T other); } class Base : ISomeInterface { public virtual void DoSmth<T>(T other){ // for example do nothing } } class Derived<T2> : Base { Action<T2> MyAction {get;set;} public override void DoSmth<T>(T other){ if(typeof(T2).IsAssignableFrom(typeof(T))) MyAction((T2) other); } } This gives me an error: Cannot...

Possible to add a new class that can be cast to an existing final class?

java,class,casting,final
I have class A defined in a library: public final class A {blah} And then I want to hack it somewhere using a new class B to substitute it: A a = new A(); A a = (A) new B(); B has all the methods and members in A, so...

How can I convert an Int array into a String? array in Swift

ios,arrays,swift,casting,type-conversion
I have an array that looks like this: var arr: [Int] = [1,2,3,4,5] In order to print this, I would like to convert this to: var newArr: [String?] = ["1","2","3","4","5"] Please help me out! Thanks in advance....

Java, store in byte higher value than 127

java,casting,byte
For an assignment I get some bytes, make some calculations on their Binary values and have to return that calculated Stuff in a Byte Array. My Problem is now, that byte only stores up to 127, but my values can be up to 2^8-1 (11111111). I already tried to convert...

what is the use of “static_cast” in macro?

c++,casting
I'm seeing a macro definition like this: #define ASSERT_VALID_PARAM(param, assertion) { static_cast<void>(param); if (!(assertion)) { throw InvalidParamError(#param, #assertion, __FILE__, __PRETTY_FUNCTION__, __LINE__); } } I'm not able to figure out the need of static_cast<void>(param) here. Any idea on why this is needed?...

How to cast subclass object to superclass object

java,inheritance,casting,subclass,superclass
i have 2 classes, called superclass and subclass, i tried to cast the subclass object to superclass, but its seems does not work when i want to use the subclass object from the superclass. Please help to explain. Thanks. These are the code:- public class superclass { public void displaySuper()...

Unwanted typecast in foreach

php,foreach,casting
I am using a function to clean variables for security purposes. However, this function convert each value into a string datatype, which I don't want. So in example, when the input parameter is a integer datatype, the function return a string datatype. Any idea how to return the exact same...

Inheritance and Casting error (generic interfaces)

c#,generics,casting,covariance
How can I restructure my code to get rid of the runtime error happening at the point indicated? DataSeries<SimpleDataPoint> needs to be able to cast back to IDataSeries<IDataPoint> somehow I have tried using inheritance of two interfaces, like this: public class DataSeries<TDataPoint> : IDataSeries<TDataPoint>, IDataSeries<IDataPoint> but received compiler error: 'DataSeries<TDataPoint>'...

Need help to understand deserialization with ArrayList in Java

java,serialization,arraylist,casting,deserialization
I want write an ArrayList to a file and then read it back again. The list is going to hold Integer objects. Serialization seems to be working fine but I'm having trouble deserilaizing. More specifically I can'get the casting right. The serialization: ObjectOutputStream ou = new ObjectOutputStream(new FileOutputStream(new File("load.dat"))); ArrayList<Integer>...

type casting in objective-c, (NSInteger) VS. integerValue

ios,xcode,casting
I don't very understand about the diference between (NSInteger)aNumberValue and [aNumberValue integerValue], then do some test. For example, here is a response data from server: You can see it's an int but the value is hold by NSNumber. I retrieve the data by writting NSInteger count = (NSInteger) dic[@"count"];, and...

Different methods for casting an object in Java

java,casting
I know the three following methods that can be used for casting objects. Object o = "str"; String str1 = (String) o; // Method 1 String str2 = o.toString(); // Method 2 String str3 = String.class.cast(o); // Method 3 Which approach is better, and what are the pros/cons of one...

What is the significance of (int*) in this program?

c++,c,pointers,casting
I wrote two programs which prints out the variable the pointer p points to: First program: #include <stdio.h> int main (void){ int *p; int a=5, q; p=&a; q=*p; printf("%d", q); } Second program: #include <stdio.h> int main(void) { int a=5; int*p; p= (int*)&a; printf("%d", *p); return 0; } My question:...

What is meant by this cast? (int (*)[10])

c,casting
I stumbled across the following cast: (int (*)[10]) In my opinion, this is a "pointer to pointer to int". Let's assume the following array declaration: int array[10]; Then I would assume that &array is of type (int (*)[10]) Is this correct?...

Typecasting over a message queue in c

c,linux,casting,ipc
I am currently trying to send an integer over a message queue. I am typecasting the address of this integer to a (char *) since in the future I would like to accept other data types and this data is sent in a struct designed for use in message queues....

Converting IEnumerable to Dictionary

c#,dictionary,casting,ienumerable,deferred-execution
after adding bool distinct to method Splitter and checking if distinct is true the code broke. The quesry now instead of being dictionary is IEnumerable<string>, but whould be Dictionary<string, int>. How could it be solved? This is the error: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.Dictionary'. An explicit conversion exists...

Defining a “vector_cast” template function that works with a variable amount of nested vectors

c++,vector,casting,nested
I want to be able to do something like this for example. std::vector<std::vector<int>> e = {{ 1 },{ 2 }}; std::vector<std::vector<double>> q = {{1.5},{2.5}}; q = vector_cast<double>(e); But also have vector_cast be able to handle any number of nested vectors. Here is my attempt at this. The code works if...

Casting error from deserialized json in c# using newton json

c#,json,serialization,casting,json.net
Unable to cast to int from deserialized json (dictionary object) Here is the code: Lets say you have dictionary object. Dictionary<string, object> dict = new Dictionary<string, object>(); dict.Add("key", 1); Now i serialize & deserialize it. var serializedData = JsonConvert.SerializeObject(dict); var deserializedData = JsonConvert.DeserializeObject<Dictionary<string, object>>(serializedData); And getting error when i do...

What is this type 'literal' syntax in Postgres?

postgresql,casting,postgresql-9.4
The Postgres docs say a cast should look like... expression::typename typename(expression) cast(expression as typename) But this works: select date '2015-06-20'; What is that syntax? Where is it documented?...