casting

Error - void* - unknown size

我只是一个虾纸丫 提交于 2019-12-23 04:36:31
问题 This function which I received from a third party contains the following code which does not compile in MS Visual Studio 10. I think there is a casting problem but do not know how to fix this. void dump_ffmpeg_pad16(FILE *stream, uint32_t timestamp, void *data, int data_size) { unsigned int z=0; void *end = data + data_size; while (data < end) { z = *(unsigned short*)data; fwrite(((char*)(&z)), 3, 1, stream); data += 2; } } It has been instructed in their help to compile as C++ code. Thanks

Running a Quartz job with Java class name stored in database

醉酒当歌 提交于 2019-12-23 04:33:13
问题 I have a two jobs in Quartz which will run perfetly well but I find I have to use code like: jd = new JobDetail(sj.getJobName(), scheduler.DEFAULT_GROUP, PollJob.class); ct = new CronTrigger(sj.getJobTrigger(), scheduler.DEFAULT_GROUP, "0 20 * * * ?"); scheduler.scheduleJob(jd, ct); I have to hardcode PollJob.class to run the job and sj is an object read from the database containing PollJob's details. But I would like to set PollJob.class from the database as well. I've tried casting to a

Using typeid for simple decisions

馋奶兔 提交于 2019-12-23 03:47:11
问题 My question concerns simple catching of casting problems at runtime in C++. I understand that C++ provides no 'RTTI' under most circumstances (let's just say I can't change my compiler settings and turn it on, for argument's sake.). In my project, I have a container provided to me by an ancient library. Let's call that Frodo and the container Bane. Frodo's Bane is a container I must interact with directly. It has been poorly implemented and contains several maps of the same information which

Generic Quadtree

淺唱寂寞╮ 提交于 2019-12-23 03:28:05
问题 I am writing a quadtree class as a part of graphics library and I am facing a design issue. A main goal is to allow the user of the library to easily extend the quadtree with their own Node Types. Each node has a pointer to the first of its four childs. I use the protoype pattern to 'clone' a parent node (its real type is unknown to the library) four times when it is split. So here is the Node class: class CNode { public: virtual CNode* clone(); protected: CNode* pChilds; } The user of the

How to initialize CastContext outside of onCreate method

主宰稳场 提交于 2019-12-23 03:03:04
问题 I would like to only activate the Cast feature due to certain criteria so I don't want any Cast logic in my onCreate. I have a setupCast method that has the following code: private void setupCast(String appId) { if (appId != null) { Log.d(TAG, "Setting up Cast..."); setupCastListener(); CastOptionsProvider.setAppId(appId); mCastContext = CastContext.getSharedInstance(_movieActivityContext); mCastContext.registerLifecycleCallbacksBeforeIceCreamSandwich(this, _savedInstanceState); mCastSession

Sending in an object of type Object instead of String - Polymorphism

孤街浪徒 提交于 2019-12-23 02:47:26
问题 I've an existing method which looks like this: public void parseMessage(String message){ ... ... ... } and the method is called by calling it as shown below String message; parseMessage(message); I need to modify it for it to process a new type of message. The parser for the new type of message which is called from the parseMessage method expects some properties first before it can parse the message. What i am thinking of doing is passing the message as an object that looks like this public

How to use printf with mpfr and mpreal

左心房为你撑大大i 提交于 2019-12-23 01:05:08
问题 What is the correct syntax for using printf and its cousins sprintf and fprintf to display the value of mpreal -type variables? I have tried the naive casting to double: printf ("... %g ...", (double) var); only to receive this error message from g++: error: invalid cast from type ‘mpfr::mpreal’ to type ‘double’ I had no problem using double -type variables elsewhere on the program. I heard about the type mpreal as part of this library intended to enable the use of the usual binary operators

How to use printf with mpfr and mpreal

怎甘沉沦 提交于 2019-12-23 01:04:57
问题 What is the correct syntax for using printf and its cousins sprintf and fprintf to display the value of mpreal -type variables? I have tried the naive casting to double: printf ("... %g ...", (double) var); only to receive this error message from g++: error: invalid cast from type ‘mpfr::mpreal’ to type ‘double’ I had no problem using double -type variables elsewhere on the program. I heard about the type mpreal as part of this library intended to enable the use of the usual binary operators

Converting MD5 result into an integer in C

假如想象 提交于 2019-12-22 20:45:06
问题 My goal is to use the result of an MD5 result to index a hash table. I want to perform a Modulo operation on it to find the appropriate slot in the table. I have tried casting it as an unsigned long long type. When I printed the result, I got a different number every time for the same MD5 hash. The MD5 hash is initially an unsigned char *. Can someone tell me what I am doing wrong? Here is my function: int get_fp_slot(unsigned char * fingerprint, int size) { return (unsigned long long

How can this [AnyObject] return as AnyObject?

痞子三分冷 提交于 2019-12-22 18:45:12
问题 import Cocoa class Brain{ var internalProgram = [AnyObject]() var program:AnyObject{ get{ return (internalProgram as AnyObject) } } } var savedProgram: AnyObject? let brain = Brain() func save(){ savedProgram = brain.program } How can this internalProgram:[AnyObject] return as AnyObject without Xcode giving a warning or an error? I know that program 's type is set as AnyObject already but I mean how can this work and wasn't it supposed to be [AnyObject] ? So why no any warning or error issue?