casting

Cast function pointers that differs by argument type

一曲冷凌霜 提交于 2019-12-11 20:18:30
问题 Why this is not legal: class Base { public: Base(){}; virtual ~Base(){}; }; class Derived : public Base{}; void takeDerived(Derived * c){}; // main void(*ptr)(Base*) = static_cast<void(*)(Base*)>(&takeDerived); // doesn't work // but this work ok, as well as reinterpret_cast // void(*ptr)(Base*) = (void(*)(Base*))(&takeDerived); Derived is a Base . Why can't it be casted in function parameter? For example, I can do this easily even without casting: void takeBase(Base* c){}; takeBase(new

cast from Eigen::CwiseBinaryOp to MatrixXd causes segfault

烂漫一生 提交于 2019-12-11 19:40:06
问题 I am writing a library that stores Eigen expression templates as member variables to do the complicated calculations it needs to do. However, it seems like I'm not able to store or return these expression templates unless they are directly converted in MatrixXd or alike. This forces every step to be saved to a temporary, and ruins the efficiency of the whole design. Here's a short example that causes the trouble. Holder just holds an Eigen matrix, and Summer takes two holders and outputs the

ASP.NET MVC: types cast in model binding

送分小仙女□ 提交于 2019-12-11 19:29:52
问题 Is there a way to cast parameter in the controller's action from one type to another in ASP.NET MVC 5? Example. Action method is the following: public string Test(Guid input) { return ""; } If the method is invoked with parameters "input=hello" then I get the error with the message: "The parameters dictionary contains a null entry for parameter 'input' of non-nullable type 'System.Guid' for method 'System.String Test(System.Guid)' in 'RealtyGuide.WebSite.Controllers.HomeController'. An

Casting an unsigned int + a string to an unsigned char vector

五迷三道 提交于 2019-12-11 19:29:47
问题 I'm working with the NetLink socket library ( https://sourceforge.net/apps/wordpress/netlinksockets/ ), and I want to send some binary data over the network in a format that I specify. The format I have planned is pretty simple and is as follows: Bytes 0 and 1: an opcode of the type uint16_t (i.e., an unsigned integer always 2 bytes long) Bytes 2 onward: any other data necessary, such as a string, an integer, a combination of each, etc.. the other party will interpret this data according to

Avoiding casts when narrowing jooq selects

不问归期 提交于 2019-12-11 19:27:58
问题 Let's say I have a book database and I want to check whether the CLRS book has the correct authors. Assuming private static final String CLRS_title = "Introduction to Algorithms"; @Test public void CLRS_is_written_by_CLRS(){ //given SelectConditionStep<Record> query = create .select() .from( ( BOOK.leftOuterJoin(BOOK_AUTHOR).on(BOOK.ID.eq(BOOK_AUTHOR.BOOKID)) ).leftOuterJoin(AUTHOR).on(AUTHOR.ID.eq(BOOK_AUTHOR.AUTHORID)) ) .where(BOOK.TITLE.eq(CLRS_title)) ; //when Result<Record> result =

How can I get SQL Server to use User Locale for Date format for a Query?

六眼飞鱼酱① 提交于 2019-12-11 19:22:14
问题 I have created the following simple table for this test: DROP TABLE DateFieldTest CREATE TABLE DateFieldTest ( DateField Date NOT NULL ) INSERT INTO DateFieldTest VALUES ('2013-07-15') INSERT INTO DateFieldTest VALUES ('2013-07-16') INSERT INTO DateFieldTest VALUES ('2013-07-17') INSERT INTO DateFieldTest VALUES ('2013-07-05') INSERT INTO DateFieldTest VALUES ('2013-07-06') INSERT INTO DateFieldTest VALUES ('2013-07-07') INSERT INTO DateFieldTest VALUES ('2013-06-05') INSERT INTO

how to convert a list value into int

大城市里の小女人 提交于 2019-12-11 19:20:03
问题 i have a pyodbc row with value (9, ) I am trying to read the value into a simple integer variable, and i find that its so hard to do so. (i am new to python so i probably miss something dumb) doing a simple int(a_row[0]) get - TypeError: int() argument must be a string or a number, not 'pyodbc.Row' i try to cast the row into a list first, and its the same result i had to force it into a integer value to work row_id=(2, ) temp_num=0 temp_num = [number for number in row_id[0]] temp_num=int(temp

Trouble with type casting in c#

时光毁灭记忆、已成空白 提交于 2019-12-11 18:06:56
问题 I have 2 classes: class A { public void A_1(Object b) { ... Type t = b.GetType(); (t.FullName)b.B_1(); //It doesn`t work! Error in cast } .... } class B { public void B_1() { ... } .... } A a = new A(); B b = new B(); a.A1(b); How to cast object correctly? 回答1: If you want to cast an object of any type to an object of another type, you do this: // Will Throw an exception at runtime if it cant be cast. B newObject = (B)oldObject; // Will return null at runtime if the object cannot be cast B

Returning an argument pointer to an object

泄露秘密 提交于 2019-12-11 17:54:29
问题 In C++ for Windows, I have some object factory that is supposed to create a series of Info object by passing a pointer to the object to a Create function and returning a created object. void CreateInfoObject(AbstractInfo** info); // The creation function AbstractInfo is a base class of which we have many types of Info objects derive. I thought I could now create an Info object as follows: MyInfoObject* InfoObj = NULL; // derived from AbstractInfo object InfoFactory fc; fc.CreateInfoObject(

TCL: A variable stores a hex value that represents a floating point number, how can this be printed on screen as a float?

帅比萌擦擦* 提交于 2019-12-11 17:39:58
问题 The 0x3f800000 represents 1.0 in single precision floating maths. I tried this but could not get the correct result from the program: set x 0x3f800000 set y [expr double($x)] puts $y I just want to "cast" the value of x into a float so it will print on screen as float. How do I do this in tcl? Please note that in the original problem that I am trying to solve, a tcl script reads value from a hardware register in Quartus II System Console debug system. However, I have given a simple example