casting

C++ type casting with pointers

ⅰ亾dé卋堺 提交于 2019-12-21 05:39:19
问题 I come from a background of C# and Java and I can't seem to understand what casting with pointers means in C++. For example: int x = 1; char c = *((char*)&x); What does it do? What it is useful for? 回答1: In both your examples you're making mistakes making the code not compile. So I'll assume you're trying to do the following: int x = 1; char c = *((char*)&x); Depending on your architecture, c will now have either the value of the least or the most significant byte of x . In this example this

ksoap2 casting getResponse()

爷,独闯天下 提交于 2019-12-21 05:04:22
问题 Calling a .net SOAP1.1 web service from android using ksoap2 lib I met a problem of casting response to a custom object. For instance the code below is called correct after httpTransport.call(soapAction, soapEnvelope); and have data inside. But I cant't cast it to specific object neither to SoapObject or Vector as I saw in several examples, I get CastException or simple nothing. If somebody knows how to deal with it, please help. public StatusSetting[] GetAllStatuses(String installation){

Few doubts about casting operators in C++

筅森魡賤 提交于 2019-12-21 04:51:33
问题 The reinterpret_cast as we know can cast any pointer type to any another pointer type. The question I want to ask regarding this cast operator are: How does reinterpret_cast work, What is the magic(the internal implementation) that allows reinterpret_cast to work? How to ensure safety when using reinterpret_cast ? As far as i know, it doesn't guarantee of safe casting, So what precaution to take while using reinterpret_cast? What is the practical usage of this operator. I have not really

Few doubts about casting operators in C++

 ̄綄美尐妖づ 提交于 2019-12-21 04:51:10
问题 The reinterpret_cast as we know can cast any pointer type to any another pointer type. The question I want to ask regarding this cast operator are: How does reinterpret_cast work, What is the magic(the internal implementation) that allows reinterpret_cast to work? How to ensure safety when using reinterpret_cast ? As far as i know, it doesn't guarantee of safe casting, So what precaution to take while using reinterpret_cast? What is the practical usage of this operator. I have not really

dynamic cast with interfaces

那年仲夏 提交于 2019-12-21 04:34:11
问题 I have a class with implements 2 interfaces and inherits 1 class. So, generally it looks like this: class T : public A, public IB, public IC { }; There is one point in the code where I have an IB * , but could really use an A * . I was hoping that a dynamic cast would like this: IB *b_ptr = new T; // it's really more complicated, but serves the example A *a_ptr = dynamic_cast<A *>(b_ptr); unfortunately, this doesn't work. Is there a proper way to do this? Or should I implement a work around?

C++ casting static two-dimensional double array to double**

纵然是瞬间 提交于 2019-12-21 04:21:02
问题 I have such matrix in my program: double m[3][4] = { {2, 4, 5, 7}, {4, 5, 1, 12}, {9, 12, 13, -4} }; And I'd like to cast it to double** type. I've already tried simple double** a = (double**)m; , but it doesn't work (when I try to read any value, I get "Access violation reading location 0x00000000.", which means I'm trying to read from NULL adress. I found almost working solution: double *b = &m[0][0]; double **c = &b; It works when I read field c[0][any] But same NULL adress reading problem

How to dynamically cast an object of type string to an object of type T

安稳与你 提交于 2019-12-21 04:18:15
问题 I have this XML document <AdditionalParameters> <PublishToPdf Type ="System.Boolean">False</PublishToPdf> </AdditionalParameters> in my code and I'm trying to build an array of arguments containing the <PublishToPdf> node. object test = (object) ((typeof(publishNode.Attributes["Type"].value)) publishNode.InnerText); This breaks at compile time of course. I can't figure out how to cast the publishNode.InnerText('false') to a runtime defined object of type specified in the XML file and store it

Typescript casting object's property

寵の児 提交于 2019-12-21 03:58:26
问题 I'm working with indexeddb and typescript. My issue is that TS doesn't seem to be able handle the event.target.result property. Case in point: request.onsuccess = (event) => { namespace.db = event.target.result; //the property 'results' does not //exist on the value of type 'EventTarget' var a = event.target; var b = <IDBOpenDBRequest>a; var c = b.result; // <-- magically there's a results property here version = parseInt(namespace.db.version); console.log("version: " + version); deferred

does in c++ the conversion from unsigned int to int always preserve the bit pattern?

一个人想着一个人 提交于 2019-12-21 03:43:19
问题 From the standard (4.7) it looks like the conversion from int to unsigned int, when they both use the same number of bits, is purely conceptual: If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2 n where n is the number of bits used to represent the unsigned type). [ Note: In a two’s complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). — end

Casting entire array of objects to string

会有一股神秘感。 提交于 2019-12-21 03:39:47
问题 I have an array of type object which are strings. I would like to convert them to strings. What would be the quickest way of doing so? Eg.: I have this object[] and want to convert it so it is this string[] . UPDATE: I think the problem is that some of the objects on the object[] are actually other objects like integers. I would need to convert them to strings first. Please include that into your solution. Thanks. 回答1: Probably not the most efficient way to do it...it has the benefit of