casting

How do you convert a 'System::String ^' to 'TCHAR'?

岁酱吖の 提交于 2020-01-11 10:25:32
问题 i asked a question here involving C++ and C# communicating. The problem got solved but led to a new problem. this returns a String (C#) return Marshal.PtrToStringAnsi(decryptsn(InpData)); this expects a TCHAR* (C++) lpAlpha2[0] = Company::Pins::Bank::Decryption::Decrypt::Decryption("123456"); i've googled how to solve this problem, but i am not sure why the String has a carrot(^) on it. Would it be best to change the return from String to something else that C++ would accept? or would i need

is cast a pointer points-to-class to it's first member illegal?

谁说胖子不能爱 提交于 2020-01-11 10:17:32
问题 I see some strange code in our project like follows.I test it and get the right answer.But I think it is illegal,Can anyone explain this to me? class Member { public: Member(): a(0),b(1) {} int a; int b; }; // contains `Member` as its first member class Container { public: Container(): c(0),d(0) {} Member getMemb(){return fooObject;} Member fooObject; int c; int d; }; and how we use it: int main() { auto ctain = new Container; auto meb = (Member *)ctain; // here! I think this is illegal cout

is cast a pointer points-to-class to it's first member illegal?

无人久伴 提交于 2020-01-11 10:17:29
问题 I see some strange code in our project like follows.I test it and get the right answer.But I think it is illegal,Can anyone explain this to me? class Member { public: Member(): a(0),b(1) {} int a; int b; }; // contains `Member` as its first member class Container { public: Container(): c(0),d(0) {} Member getMemb(){return fooObject;} Member fooObject; int c; int d; }; and how we use it: int main() { auto ctain = new Container; auto meb = (Member *)ctain; // here! I think this is illegal cout

How to convert a string to an integer in a JSON file using jq?

て烟熏妆下的殇ゞ 提交于 2020-01-11 08:05:29
问题 I use jq to transform a complex json object into a tinier one. My query is: jq 'to_entries[]| {companyId: (.key), companyTitle: (.value.title), companyCode: (.value.booking_service_code)}' companies.json Now, the (.key) is parsed as a string, yet I want companyId to be a number. My result currently looks like this: { "companyId": "1337", "companyTitle": "Some company title", "companyCode": "oxo" } yet it should be like: { "companyId": 1337, "companyTitle": "Some company title", "companyCode":

C++ casting programmatically : can it be done?

走远了吗. 提交于 2020-01-11 05:26:20
问题 Let's say I have a Base class and several Derived classes. Is there any way to cast an object to one of the derived classes without the need to write something like this : string typename = typeid(*object).name(); if(typename == "Derived1") { Derived1 *d1 = static_cast&lt Derived1*&gt(object); } else if(typename == "Derived2") { Derived2 *d2 = static_cast &lt Derived2*&gt(object); } ... else { ... } 回答1: Don't. Read up on polymorphism. Almost every "dynamic cast" situation is an example of

Does (size_t)((char *)0) ever not evaluate to 0?

*爱你&永不变心* 提交于 2020-01-11 05:21:27
问题 According to the responses in "Why subtract null pointer in offsetof()?" (and my reading of K&R), the C standard doesn't require that (size_t)((char *)0) == 0 . Still, I've never seen a situation where casting a null pointer to an integer type evaluates to anything else. If there is a compiler or scenario where (size_t)((char *)0) != 0 , what is it? 回答1: Well, as you know, the physical representation of null pointer of a given type is not necessarily all-zero bit pattern. When you forcefully

PostgreSQL: convert hex string of a very large number to a NUMERIC

偶尔善良 提交于 2020-01-11 05:20:08
问题 I am trying to convert hex string of a very large number to a NUMERIC column CREATE OR REPLACE FUNCTION hex_to_int(hexval varchar) RETURNS NUMERIC AS $$ DECLARE result NUMERIC; BEGIN EXECUTE 'SELECT x''' || hexval || '''::NUMERIC(40,0)' INTO result; RETURN result; END; $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; There I am trying to do this: select hex_to_int(tx.value) from internal_transaction tx The error I get is : [42846] ERROR: cannot cast type bit to numeric Where: PL/pgSQL function hex_to

Implicit cast to string - toString and int + “”

此生再无相见时 提交于 2020-01-10 04:57:10
问题 Why when i use this: int a = 1; methodWithParamString(a + ""); a is cast to String, bu i can't use toString() on integer? int a = 1; methodWithParamString(a.toString()); Doesn't this: a+"" works like: a.toString() + "" ? 回答1: No, it works like String.valueOf( a ) + "" , which in turn behaves like new StringBuilder( String.valueOf( a ) ).append( "" ).toString() . The important thing to know is that it's all just done by the compiler, in other words it's syntactic sugar. This is why adding

Cast void pointer to integer array

会有一股神秘感。 提交于 2020-01-09 19:26:27
问题 I have a problem where I have a pointer to an area in memory. I would like to use this pointer to create an integer array. Essentially this is what I have, a pointer to a memory address of size 100*300*2 = 60000 bytes unsigned char *ptr = 0x00000000; // fictional point in memory goes up to 0x0000EA60 What i would like to achieve is to examine this memory as an integer array of size 100*150 = 15000 ints = 60000 bytes, like this: unsigned int array[ 100 ][ 150 ]; I'm assuming it involves some

Cast void pointer to integer array

南笙酒味 提交于 2020-01-09 19:25:28
问题 I have a problem where I have a pointer to an area in memory. I would like to use this pointer to create an integer array. Essentially this is what I have, a pointer to a memory address of size 100*300*2 = 60000 bytes unsigned char *ptr = 0x00000000; // fictional point in memory goes up to 0x0000EA60 What i would like to achieve is to examine this memory as an integer array of size 100*150 = 15000 ints = 60000 bytes, like this: unsigned int array[ 100 ][ 150 ]; I'm assuming it involves some