casting

Non-member conversion functions; Casting different types, e.g. DirectX vector to OpenGL vector

会有一股神秘感。 提交于 2020-03-11 18:13:40
问题 I am currently working on a game "engine" that needs to move values between a 3D engine, a physics engine and a scripting language. Since I need to apply vectors from the physics engine to 3D objects very often and want to be able to control both the 3D, as well as the physics objects through the scripting system, I need a mechanism to convert a vector of one type (e.g. vector3d<float> ) to a vector of the other type (e.g. btVector3 ). Unfortunately I can make no assumptions on how the

Non-member conversion functions; Casting different types, e.g. DirectX vector to OpenGL vector

元气小坏坏 提交于 2020-03-11 18:13:30
问题 I am currently working on a game "engine" that needs to move values between a 3D engine, a physics engine and a scripting language. Since I need to apply vectors from the physics engine to 3D objects very often and want to be able to control both the 3D, as well as the physics objects through the scripting system, I need a mechanism to convert a vector of one type (e.g. vector3d<float> ) to a vector of the other type (e.g. btVector3 ). Unfortunately I can make no assumptions on how the

How to cast self to UnsafeMutablePointer<Void> type in swift

≡放荡痞女 提交于 2020-03-04 23:16:54
问题 Trying to pass "self" to a C function in swift, when calling following code: var callbackStruct : AURenderCallbackStruct = AURenderCallbackStruct.init( inputProc: recordingCallback, inputProcRefCon: UnsafeMutablePointer<Void> ) What is the ideal way to cast "self" to a UnsafeMutablePointer type here? 回答1: An object pointer (i.e. an instance of a reference type ) can be converted to a UnsafePointer<Void> (the Swift mapping of const void * , UnsafeRawPointer in Swift 3) and back. In Objective-C

PHP: Understanding string type juggling

痞子三分冷 提交于 2020-03-04 08:45:29
问题 If I set $var to a string in PHP, that variable will evaluate to true in any conditions: $var = "foo"; if ( $var ) { echo 'I will be printed'; } else { echo 'I will not be printed'; } I understand that my condition above automatically does type juggling so that $var is converted in a bool . Now, if I cast $var to an integer , I get 0 : var_dump( (int)$var ); // int(0) 0 is a falsy value which becomes false when converted to a bool : $zero = 0; var_dump( (bool)$zero ); // bool(false)

Return copy of case class from generic function without runtime cast

落花浮王杯 提交于 2020-02-26 18:24:32
问题 I want to get rid of a runtime cast to a generic ( asInstanceOf[A] ) without implicit conversions. This happens when I have a fairly clean data model consisting of case classes with a common trait and want to implement a generic algorithm on it. As an example the resulting algorithm should take a class of type A that is a subclass of the trait T and is supposed to return a copy of the concrete class A with some updated field. This is easy to achieve when I can simply add an abstract copy

Why casting an open array parameter to an array type causes E2089 Invalid typecast?

和自甴很熟 提交于 2020-02-24 00:34:13
问题 I'm using Delphi 2007 (Pre generics) and I've defined many functions who can be used for all arrays of TObject 's descendants, example: function IndexOf(AArray : array of TObject; AItem : TObject) : integer; begin //... end; For passing them dynamic arrays of TObject 's descendants, I've defined an array type TObjectArray = array of TObject . In this way I can cast dynamic arrays and pass them to my functions without any problems: type TChild = class(TObject); ... procedure Test(); var Items

Is converting an integer to a pointer always well defined?

偶尔善良 提交于 2020-02-21 13:56:33
问题 Is this valid C++? int main() { int *p; p = reinterpret_cast<int*>(42); } Assuming I never dereference p . Looking up the C++ standard, we have C++17 §6.9.2/3 [basic.compound] 3 Every value of pointer type is one of the following: a pointer to an object or function (the pointer is said to point to the object or function), or a pointer past the end of an object ([expr.add]), or the null pointer value ([conv.ptr]) for that type, or an invalid pointer value. A value of a pointer type that is a

Is converting an integer to a pointer always well defined?

孤者浪人 提交于 2020-02-21 13:45:36
问题 Is this valid C++? int main() { int *p; p = reinterpret_cast<int*>(42); } Assuming I never dereference p . Looking up the C++ standard, we have C++17 §6.9.2/3 [basic.compound] 3 Every value of pointer type is one of the following: a pointer to an object or function (the pointer is said to point to the object or function), or a pointer past the end of an object ([expr.add]), or the null pointer value ([conv.ptr]) for that type, or an invalid pointer value. A value of a pointer type that is a

Is converting an integer to a pointer always well defined?

隐身守侯 提交于 2020-02-21 13:43:05
问题 Is this valid C++? int main() { int *p; p = reinterpret_cast<int*>(42); } Assuming I never dereference p . Looking up the C++ standard, we have C++17 §6.9.2/3 [basic.compound] 3 Every value of pointer type is one of the following: a pointer to an object or function (the pointer is said to point to the object or function), or a pointer past the end of an object ([expr.add]), or the null pointer value ([conv.ptr]) for that type, or an invalid pointer value. A value of a pointer type that is a

No suitable conversion function from “std::string” to “const char *” exists

别说谁变了你拦得住时间么 提交于 2020-02-14 04:10:07
问题 I am trying to delete a .txt file but the filename is stored in a variable of type std::string . The thing is, the program does not know the name of the file beforehand so I can't just use remove("filename.txt"); string fileName2 = "loInt" + fileNumber + ".txt"; Basically what I want to do is: remove(fileName2); However, it tells me that I cannot use this because it gives the me error: No suitable conversion function from "std::string" to "const char *" exists. 回答1: remove(fileName2.c_str());