casting

Error C2440 : cannot cast 'System::Drawing::Bitmap' into 'System::Object'

老子叫甜甜 提交于 2019-12-13 03:54:57
问题 I recently started tu use OpenCV in an effort to integrate plugins based on it to an already existing project. This one uses System::Drawing::Bitmap to manage images and a System::EventArgs derivative (not sure about that word) containing a System::Object element used to transfer data between plugins. OpenCV beeing in C++ I have to program my plugin accordingly but thanks to CLR (not very sure about that one) my new c++ class can inherit my C# "Plugin" interface. This one plugin is pretty

Java method with generic return Type

北战南征 提交于 2019-12-13 03:41:25
问题 Is there a way in Java to return different types with one declaration of a method? public Object loadSerialized(String path) { Object tmpObject; try { FileInputStream fis = new FileInputStream(path); ObjectInputStream ois = new ObjectInputStream(fis); tmpObject = (Object) ois.readObject(); ois.close(); fis.close(); return tmpObject; } catch (FileNotFoundException e) { return null; } catch (Exception e) { } } I want this method to return an Object and I cloud cast it to the right type at the

L-value trouble when using a (void *) as a generic data container

梦想与她 提交于 2019-12-13 03:38:57
问题 Here is a structure used in a program: struct basic_block { void * aux; /* Many other fields, which are irrelevant. */ }; Now: Several instances of basic_block exist during the execution of the program. The program works in stages/passes, which are executed one after another. The aux field is meant for storing stage and basic_block specific data during the execution of a stage, and freed by the stage itself (so the next stage can reuse it). This is why it is a void * . My stage uses aux to

OpenCV casting of vector<Point>.data to Point* resulting in an unexpected behaviour

自闭症网瘾萝莉.ら 提交于 2019-12-13 03:24:20
问题 In a OpenCV C++ program I have a function with this body. for (int ii=0; ii< static_cast<int>(parks.size()); ii++) { PolygonVertices temp = parks.at(ii).getPoly(); const Point *pts = (const cv::Point*) Mat(parks.at(ii).getPoly()).data; int npts = Mat(parks.at(ii).getPoly()).rows; for (int jj=0; jj<npts; jj++) { cout<<"----"<<jj<<"----"<<endl; cout<<"x: "<<pts[jj].x<<", y: "<<pts[jj].y<<endl; cout<<"x: "<<temp[jj].x<<", y: "<<temp[jj].y<<endl; cout<<"--------"<<endl; } } } Polygonvertices is a

how to insert a CvPoint into a CvSeq with cvInsert?

ε祈祈猫儿з 提交于 2019-12-13 03:19:41
问题 I'm using a CvSeq of Cvpoint and it is created by cvApproxPoly. I need to delete some points and insert some new ones. I can delete the points with any problem, but when I try to insert I get an error: "cannot convert parameter 3 from "CvPoint" to "const void *" the code I wrote is Cvpoint p; p.x=1; p.y=1; cvInsert (mySeq, i, p); how do I typecast p? 回答1: try cvSeqPush call it as Cvpoint p; p.x=1; p.y=1; cvSeqPush(mySeq, &p); 来源: https://stackoverflow.com/questions/8312102/how-to-insert-a

Why std::string does not have (explicit) const char* cast

青春壹個敷衍的年華 提交于 2019-12-13 02:55:30
问题 I like to know pro's and con's for having and not-having such cast. At several places including here on Stack Overflow I can see that the const char* cast is considered bad idea but I am not sure why? Lack of the (const char*) and forcing to always use c_str() cast creates some problems when writing generic routines and templates. void CheckStr(const char* s) { } int main() { std::string s = "Hello World!"; // all below will not compile with // Error: No suitable conversion function from "std

c# COM Objects issue

牧云@^-^@ 提交于 2019-12-13 02:38:18
问题 Background I am working on a trading ActiveX API in visual studio 2010 on C#. Since it is an ActiveX API, I simply added the ActiveX as my reference. The api provides three group of things: Method you could use to call API, the Event with which the API updates information for you and some socalled ActiveX COM object. ISSUE I asked a related question here: C# boolean int conversion issue Finally, after viewing the exception has been thrown, I know that it is about casting. Here is the

Is a Guid a primitive type or a complex type? [closed]

爱⌒轻易说出口 提交于 2019-12-13 02:13:54
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . We separate out extension method classes by primitive types and complex types that we are extending. My question is simple. Would a Guid be considered a primitive type along with string, int, DateTime, etc? Or

A cannot be cast to B exception

点点圈 提交于 2019-12-13 01:47:48
问题 I have a piece of code in my project which, in certain situations can be run in an IIS worker process (inside a HttpHandler) and also by a separate Windows service. There is a referenced assembly (DataVisualisation.dll) which I wrote which is used by both the website components and the Windows service, and both the website and the service have their own copy of the DLL. [A]DataVisualisation.ReportingTimePeriod cannot be cast to [B]DataVisualisation.ReportingTimePeriod. Type A originates from

Convert complex<int16_t> to complex<double>

走远了吗. 提交于 2019-12-13 01:35:19
问题 Is there anyway in C++11 to do this: std::complex<int16_t> integer(42,42); std::complex<double> doub(25.5,25.5); std::complex<double> answer = integer*doub; The error is error: no match for ‘operator*’ (operand types are ‘std::complex<short int>’ and ‘std::complex<double>’) std::complex<double> answer = integer*doub; I have tried static_cast like; std::complex<double> answer = static_cast<std::complex<double>>(integer)*doub; 回答1: There's no predefined convertion from complex<double> to