casting

C++ cast to void

一曲冷凌霜 提交于 2019-12-24 12:35:00
问题 As I understand, C++ standard says that casting to void is correct only in case of function-style casting ( ISO/IEC 14882:2003, 5.2.3 ). But I can't find anything about C-style casting to void in C++ standard. Is behavior of program only implementation-defined in this case ? 回答1: As I understand, C++ standard says that casting to void is correct only in case of function-style casting No, it can be done by static_cast , and therefore also by conversions using functional or cast notation. But I

Getting 'Unable to cast object of type' error when trying to loop through Button controls on Form

巧了我就是萌 提交于 2019-12-24 12:20:59
问题 In a Form , I added a TableLayoutPanel , and within that I add 5 buttons. At runtime, I add 10 buttons to Form1 in a loop. Then I use foreach to do something with those 10 buttons. foreach (Button C in this.Controls) // do something When I the run the program, an error appears: Unable to cast object of type 'System.Windows.Forms.TableLayoutPanel' to type 'System.Windows.Forms.Button' I think this error happens because the TableLayoutPanel contains 5 buttons in it. Yeah I can delete this

Assigning a Parent object to a Child object Without casting in Java

狂风中的少年 提交于 2019-12-24 12:07:46
问题 I have a parent interface and a child interface which objects will implement. I've made a child interface because I want a specific VehicleEntity object say Truck to add itself to the HashMap in Car . A Truck will call VehicleManager's addToCar() method which add the Truck object into Car's hashMap. The issue I have is CarEntity ce = ve; . Netbeans is telling me to cast ve to CarEntity but I don't want to. Shouldn't the line of code be valid (assuming the the object the for loop is looking at

Unexpected cast to AppCompatButton: layout tag was Button

江枫思渺然 提交于 2019-12-24 12:03:57
问题 From AppCompatButton reference page: This will automatically be used when you use Button in your layouts. You should only need to manually use this class when writing custom views. I'm casting a normal Button to AppCompatButton , so that I can use setSupportBackgroundTintList method: AppCompatButton button = (AppCompatButton) findViewById(R.id.normalButton); button.setSupportBackgroundTintList(ColorStateList.valueOf(tintColor)); It builds and runs without any problem, but Android Studio 1.4

Java: Cast String to primitive type dynamically

时间秒杀一切 提交于 2019-12-24 12:01:41
问题 I want to invoke a method by reflection in java. I have on my hand the Method instance of the method I want to invoke (so I can get the types of its parameters), in addition, I have the values of these parameters as Strings. I have an assumption that all the parameters MUST be primitives. for example, if I want to invoke the following method: public static double calc(int a, double b, String op){...} I have the parameter as a String Array: String[]: {"25", "34.45", "add"} So, how can I

Typecasting string and strdup

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 12:01:20
问题 If an input const string is being modified in some way (which is resulting in C compiler warning), what is the best way to handle it - typecasting it to a new variable and then using it OR duplicating it and using it and then freeing it. Or is there any other way to handle this type of scenario. please suggest. Any help would be appreciated. //Typecasting const char * s1; char * s2 = (char *)s1; //Duplicate and free const char * s1; char * s2 = strdup( s1 ); free(s2) EDIT: It is a C compiler;

Error thrown when trying to convert from MongoDB BsonArray to IEnumerable<Users> a collection of a POCO instances

ぐ巨炮叔叔 提交于 2019-12-24 11:53:36
问题 All: Here is the information about my development environment: MongoDB 3.0.0 MongoDB C# Driver Version 1.7.0.4714 Microsoft Visual Studio Professional 2013 .NET Framework 4.0 Here is one of the POCO Classes that is used in our project: public class AppUsers { public Object Id { get; set; } public int UserID { get; set; } public int CompanyID { get; set; } public string Username { get; set; } public string Password { get; set; } public int RoleID { get; set; } public DateTime LoginTime { get;

casting void* to std::function

陌路散爱 提交于 2019-12-24 11:15:35
问题 I have an issue. I'm trying to convert a void* to std::function. This is just a simple example, any suggestions will be appreciated #.h file class Example { public: Example(); int foo(void* hi); int fooFunc(std::function<int(int, int)> const& arg, int x, int y) { foo(arg.target<void*>(), x, y); return 2; } }; #.cpp file Example::Example() { } int Example::foo(void * func, int x, int y) { //cast back to std::function func(x, y); std::cout << "running in foo: " << a << "\n"; return a; } Every

Casting the results of a volatile expression to void

梦想的初衷 提交于 2019-12-24 11:08:24
问题 Note: This is Not the same thing that has been asked many times. Yes I have read the many many posts about casting to void. None of those questions resulted in the answer I suspect is true here. Background info: Embedded C. This is specifically related to memory mapped volatile pointers. In other words, peripheral registers. I came across the following line in a routine that involves writing to an I2C peripheral: (void) I2C1->SR2; I2C1 is #defined as a struct * to volatile memory. So the

How to convert json response into an object without explicitly coding it in TypeScript (Angular 6)?

别说谁变了你拦得住时间么 提交于 2019-12-24 10:48:01
问题 In my little project, part of the functionality is to manage project entities. I created a class that looks like this: export class IdRef { id: number; } export class Project { id?: number; title: string; background?: string; problemStatement?: string; owner: IdRef; createdBy: IdRef; dateCreated: string; updatedBy?: IdRef; lastUpdated?: string; getDateCreated(): Moment { return moment(this.dateCreated); } getLastUpdated(): Moment { if (this.lastUpdated) { return moment(this.lastUpdated); }