MATLAB: Call C++ class from Matlab

cc plus plus

Is it possible to call C++ classes from Matlab? When I use loadlibrary to load a DLL into Matlab, I get the following errors:
Warning: The data type 'error' used by function CLASSNAME does not exist.
> In loadlibrary at 421
Warning: The function 'CLASSNAME' was not found in the library
> In loadlibrary at 421
Would creating a MEX file be any different than using loadlibrary?

Best Answer

Only functions which are
extern "C"
can be called from MATLAB. Those routines have no "this", so only static class methods can be directly called. Those routines can create new objects or reference existing objects, but you cannot pass objects in from MATLAB and cannot return objects to MATLAB.