casting

Casting a Boost FileSystem3 iterator to a const char*

筅森魡賤 提交于 2019-12-11 06:34:28
问题 I'm looping over some file in a directory using Boost FileSystem 3 and I need to cast the filename to a char* for another lib, Unfortunately my C++ foo is lacking, can anyone help ? int main(int argc, char* argv[]) { path p (argv[1]); // p reads clearer than argv[1] in the following code try { if (exists(p)) // does p actually exist? { if (is_regular_file(p)) // is p a regular file? cout << p << " size is " << file_size(p) << '\n'; else if (is_directory(p)) // is p a directory? { cout << p <<

Casting enum value to int when binding to dropdown using reflection

微笑、不失礼 提交于 2019-12-11 06:31:23
问题 I have some code that binds an enumeration to a dropdown list, however, I'd like build the dropdown to take the integer value from the enum for the value and the description attribute for the text. I tried defining the kvPairList as a int/string and casting enumValue and an (int) I also tried converting.toInt32 Ideas? <select name="DropDownList1" id="DropDownList1"> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3/option> </select Enum: using

Assignment makes pointer from int w/out a cast

£可爱£侵袭症+ 提交于 2019-12-11 06:27:26
问题 I am compiling some code for a program that memoizes fibonacci numbers. The program works perfectly however when I compile in linux environment I get this warning before compiling. line 61: warning: assignment makes pointer from integer without a cast [enabled by default] Here is a snippet of code of where this warning is coming from, I'll try to show things of most relevance to get the best picture presented of the situation int InitializeFunction(intStruct *p, int n) p->digits = (int)malloc

C# 3.0 implicit cast error with class and interfaces with generic type

試著忘記壹切 提交于 2019-12-11 06:23:24
问题 I implemented a few dependencies (which are the part of MVP pattern). Now, when I try to perform casting, VS informs about an error. Definitions: interface IView { void setPresenter(IPresenter<IView> presenter); } interface IViewA : IView { } interface IPresenter<T> where T : IView { void setView(T view); } class PresenterA : IPresenter<IViewA> { } Implicit cast: IPresenter<IView> presenter = new PresenterA(); Compile error: Cannot implicitly convert type 'PresenterA' to 'IPresenter'. An

C# + WPF : how should I do proper checks/guards/casts when accessing control values?

风流意气都作罢 提交于 2019-12-11 06:23:13
问题 This is probably pretty basic, but I'm just picking up C# after many years working with other languages, and I've unfortunately grown used to loose and dynamic typing. Now, in building a WPF form with a lot of checkboxes, I notice that my code to do simple things like determine whether a checkbox is checked is actually quite complicated due to the need to check for nulls and cast the results. I end up with helper functions like: private bool isChecked(CheckBox control) { return control !=

Casting int to float in thymeleaf frontend

僤鯓⒐⒋嵵緔 提交于 2019-12-11 06:16:45
问题 I have something like this: <span th:text="*{a / (b + c)}"></span> where a, b and c are integers. I need the result to be a floating point number. Any ideas? Actual code: <span th:text="(*{item.candidates } > 0 and *{item.budgetSeats + item.taxSeats} > 0)?*{#numbers.formatDecimal(item.candidates / (item.budgetSeats + item.taxSeats),1,2, 'POINT')}:'N/A'"> 回答1: The answer is simple: Multiply (at least) one of the numbers with a float e.g. 1.0 . <span th:text="*{ (a * 1.0) / (b + c)}"></span> 来源

Calling C functions with too many arguments

邮差的信 提交于 2019-12-11 06:16:18
问题 I am currently changing the function signatures of a class of functions in an application. These functions are being stored in a function table, so I was expecting to change this function table as well. I have just realised that in certain instances, we already use the new function signature. But because everything is casted to the correct function type as it is put into the function table, no warnings are being raised. When the function is called, it will be passed extra parameters that are

How to prevent PHP from doing octal math in conditionals? (why does 08 === 0)

一世执手 提交于 2019-12-11 06:14:45
问题 I was working with code that parses crontab. https://stackoverflow.com/a/5727346/3774582 I found it works great, however I found that if I made a cron like 0 * * * * It would run at the 0 minute, the 8th minute, and the 9th minute. I broke down every line of the code. https://gist.github.com/goosehub/7deff7928be04ec99b4292be10b4b7b0 I found that I was getting this conditional for the value of 0 if the current minute was 8. 08 === 0 I tested this with PHP if (08 === 0) { echo 'marco'; } After

Casting don't work (int []to double[])

这一生的挚爱 提交于 2019-12-11 06:09:01
问题 I have setter method: public void setValues(int[] values){ this.values = (double[])values; } and Java don't allow me to do that. I get message about inconvertible types. I know I can use Integers and doubleValue() method but above solution should work (I think). So, what's wrong? 回答1: Casting from int to double is a different thing than casting from int[] to double[] . The later cannot work, because an array is an object. So you have 2 incompatible objects. The cast will surely fail at

MySQL BIGINT conversion to Java Long

放肆的年华 提交于 2019-12-11 06:06:18
问题 Why a MYSQL column of type bigint cannot be casted to Java Long? When using JPA.em().createNativeQuery("select ...").getResultList() and the select result is a column from the type bigint, you can't assign the result to a Long variable. The cast causes a run time exception "java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long" This of course can be solved by using a bigInteger variable and then ".longValue()" I'm trying to understand what is the underlying