Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: Making C++ objects persistent between mex calls, and robust.
Posted:
Jul 6, 2011 5:07 AM
|
|
"mathias" wrote: > the reinterpret_cast loose the type_id and therefore handling object of a class hierarchy through the mother_class and dynamic_cast is made difficult. > > For instance, imagine the class hierachy : > class A {}; > class B : public A{}; > class C : public B {}; > > imagine in "mex_function1 " you create > B * pB = new B(); > C * pC = new C(); > > then you send the pointers to matlab, and provide the pointer back to another mex function "mex_function2", and want to use a A * interface : > A * pA = createObjectPointerFromMxArray(prhs[0) > > and later on : > > pB * = dynamic_cast<B*>(pA) ; > if(NULL!=pB) etc ..... > > This will not work, since the type_id of the object is lost
I'm not sure I completely understand. If you created an instance of class B and sent it's pointer to MATLAB, why wouldn't you cast it back to a class B pointer when you re-enter a mex file?
If you want to make sure that you are casting a pointer to the correct type then you could use my wrapper class which uses a signature (code given in an earlier thread), and have a different signature for each type.
Oliver
|
|
|
|